iroha
iroha copied to clipboard
Error messages in `no_std` are useless
Due to usage of
#[cfg_attr(feature = "std", derive(thiserror::Error))]and#[cfg_attr(feature = "std", source)]
We lose a lof of info about errors. Because of that Debug print of, for example, ValidationFail error may look just like Instruction execution failed without additional info (while still containing this information in the type).
I suggest to keep the idea of source because it gives us good printing in std. But we need to fix no_std too.
Solutions I see:
- Use thiserror-core -- fork of
thiserrorwhich supportsno_std. There is a PR implementing this feature inthiserror, butthiserrormaintainer seems to completely ignore it - Feature-gated
displayimpls. Right now we just write something like#[display(fmt = "Query execution failed")]which could be refactored as:
#[cfg_attr(feature = "std", display(fmt = "Query execution failed"))]
#[cfg_attr(not(feature = "std"), display(fmt = "Query execution failed: {0}"))]
snafu may help, as it does work in no_std.
It does this via a hidden Error trait, which supports the .source mechanism.
It also has a way to shorthand wrapping errors in other errors using .context methods, albeit I am not sure how useful would this be in our codebase