Open
Description
I just saw this absolutely horrendous error message:
Error parsing JSON-AD with property https://common.terraphim.io/01jxcy0rt398wjbbz4d85fb0dp/01jx2t880df6sj29p6yaj4c76n/property/data-class. Unable to find property https://common.terraphim.io/01jxcy0rt398wjbbz4d85fb0dp/01jx2t880df6sj29p6yaj4c76n/property/data-class: Failed getting property https://common.terraphim.io/01jxcy0rt398wjbbz4d85fb0dp/01jx2t880df6sj29p6yaj4c76n/property/data-class. Error when server tried fetching https://common.terraphim.io/01jxcy0rt398wjbbz4d85fb0dp/01jx2t880df6sj29p6yaj4c76n/property/data-class : https://common.terraphim.io/01jxcy0rt398wjbbz4d85fb0dp/01jx2t880df6sj29p6yaj4c76n/property/data-class: status code 401 exception.details=Error parsing JSON-AD with property https://common.terraphim.io/01jxcy0rt398wjbbz4d85fb0dp/01jx2t880df6sj29p6yaj4c76n/property/data-class. Unable to find property https://common.terraphim.io/01jxcy0rt398wjbbz4d85fb0dp/01jx2t880df6sj29p6yaj4c76n/property/data-class: Failed getting property https://common.terraphim.io/01jxcy0rt398wjbbz4d85fb0dp/01jx2t880df6sj29p6yaj4c76n/property/data-class. Error when server tried fetching https://common.terraphim.io/01jxcy0rt398wjbbz4d85fb0dp/01jx2t880df6sj29p6yaj4c76n/property/data-class : https://common.terraphim.io/01jxcy0rt398wjbbz4d85fb0dp/01jx2t880df6sj29p6yaj4c76n/property/data-class: status code 401 http.status_code=500 otel.status_code="ERROR"}: tracing_actix_web::middleware: Error encountered while processing the incoming HTTP request: Error parsing JSON-AD with property https://common.terraphim.io/01jxcy0rt398wjbbz4d85fb0dp/01jx2t880df6sj29p6yaj4c76n/property/data-class. Unable to find property https://common.terraphim.io/01jxcy0rt398wjbbz4d85fb0dp/01jx2t880df6sj29p6yaj4c76n/property/data-class: Failed getting property https://common.terraphim.io/01jxcy0rt398wjbbz4d85fb0dp/01jx2t880df6sj29p6yaj4c76n/property/data-class. Error when server tried fetching https://common.terraphim.io/01jxcy0rt398wjbbz4d85fb0dp/01jx2t880df6sj29p6yaj4c76n/property/data-class : https://common.terraphim.io/01jxcy0rt398wjbbz4d85fb0dp/01jx2t880df6sj29p6yaj4c76n/property/data-class: status code 401
This happens because I typically create errors like so:
.map_err(|e| format!("Error when server tried fetching {} : {}", url, e))?;
I map the error, include the previous error, and add some relevant context like the subject in question. If you do this a bunch of times, you get these horrible errors like before.
What I would want:
- Readable, shorter errors
- Still a sensible trace to see what happened
- Easy to make errors from the code base, current approach isn't hard
What I don't want:
- Repetition. In the example above you see the subject in pretty much every error there. Not good.
- Just using
?
, because that gives us very unclear errors that tell nothing about the stack / called functions - Only having a very long, unreadable stack trace. I mean, I think it would be nice if that was available or logged, but I do want some main reason to be easily readable
Improve custom AtomicError
type
- We could use
std::backtrace::Backtrace
and instantiate a backtrace when we create the error - We could store the previous error in the Error, recursively
#[derive(Clone, Debug)]
pub struct AtomicError {
pub message: String,
pub error_type: AtomicErrorType,
pub subject: Option<String>,
/** Previous error */
pub source: Option<Box<dyn std::error::Error + Send + Sync + Clone>>,
}