iroha icon indicating copy to clipboard operation
iroha copied to clipboard

Error messages in `no_std` are useless

Open Arjentix opened this issue 2 years ago • 1 comments

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:

  1. Use thiserror-core -- fork of thiserror which supports no_std. There is a PR implementing this feature in thiserror, but thiserror maintainer seems to completely ignore it
  2. Feature-gated display impls. 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}"))]

Arjentix avatar Jul 12 '23 15:07 Arjentix

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

DCNick3 avatar Jul 12 '23 16:07 DCNick3