Rust's Error type error type requires both a Debug and Display implementation. One for developer debugging and one for human display. When a crowbar lambda fails it prints the errors Debug out which typically is not useful for humans but when lambda reports these errors to user Debug it what they say.
I ran some experiments and feel pretty confident that Display would be a much better way to go for the way the std::error::Error type and crates like failure represent errors for human consumption.
#[macro_use]
extern crate cpython;
#[macro_use]
extern crate crowbar;
use std::error;
use std::fmt;
#[derive(Debug)]
struct E(String);
/*impl fmt::Debug for E {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "this is a more manual debug")
}
}*/
impl error::Error for E {
fn description(&self) -> &str {
"this is a description"
}
}
impl fmt::Display for E {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "an error occured while trying perform a thing")
}
}
lambda!(|event, _| {
println!("invoked with {:?}", event);
// this produces `SystemError: Rust panic`
//panic!("nope");
// this produces `RuntimeError: E("foo")`
// but could produce `RuntimeError: an error occured while trying to perform a thing` if crowbar printed Display
let result: Result<&str, Box<_>> = Err(E("foo".into()).into());
result
});
Rust's Error type error type requires both a Debug and Display implementation. One for developer debugging and one for human display. When a crowbar lambda fails it prints the errors Debug out which typically is not useful for humans but when lambda reports these errors to user Debug it what they say.
I ran some experiments and feel pretty confident that Display would be a much better way to go for the way the std::error::Error type and crates like failure represent errors for human consumption.