-
Notifications
You must be signed in to change notification settings - Fork 18
Specialize Termination
for Result<!, Box<dyn Error>>
to report errors via the error trait
#40
Comments
Any notes or thoughts on what this might look like? |
don't forget all the similar types with auto traits: |
https://searchfox.org/rust/rev/703f2e1685a63c9718bcc3b09eb33a24334a7541/library/std/src/ffi/c_str.rs#374-400 might be a good place to start |
This is really great to see. Will this new specialized Termination impl check |
I personally definitely don't want to encourage people to put backtraces in the output of their error messages via |
Ok great, this is also what I think regarding backtraces in the Display string. I would think that the |
Possibly, but you can already override that environment variable by using |
I can very much imagine a situation where the developer of a CLI wants to control this instead of the enduser having to fiddle with env vars. |
Instead relying on specialization we could have: struct std::error::Report(Box<dyn Error>);
impl<T: Error> From<T> for Report {
fn from(error: T) -> Self {
Report(Box::new(error))
}
}
impl fmt::Debug for Report {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Error: {}", &*self.0)?;
let mut source = self.0.source();
while let Some(source) = source {
write!(f, ": {}", source)?;
source = source.source();
}
Ok(())
}
} And point people at |
Currently all errors reported via the
Termination
impl oncore::result::Result
go throughDebug
instead ofError
, which tends to be the wrong choice for errors. We have plans for fixing this via specialization but these plans are blocked on workarounds for a soundness issue and wouldn't even apply toBox<dyn Error>
because it doesn't even implement theError
trait. We cannot fix this as far as we can tell, but it turns out we probably don't need to for this specific case! Specialization already works for concrete types, so we could specialize theTermination
impl specifically forBox<dyn Error>
today, there's nothing blocking this. That way we can confidently point people towardsfn main() -> Result<(), Box<dyn Error>>
knowing that it will output the right thing.The text was updated successfully, but these errors were encountered: