iroha icon indicating copy to clipboard operation
iroha copied to clipboard

Error messages in `no_std` are useless

Open Arjentix opened this issue 1 year 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