Error messages propagating from one pallet to another is not handled that well right now.
If you use ensure_signed for example, the best you can do is:
let sender = ensure_signed(origin).map_err(|e| e.as_str())?;
This will convert the frame_system::Error object into a string, and as a result you will lose all of the great UI experiences that these errors are meant to provide.
One solution is to re-implement and map to a custom error message.
For example:
let sender = ensure_signed(origin).map_err(|_| Error::RequireSignedOrigin)?;
But then the user would need to define extra error types for every single module, since they all rely on some combination of ensure_signed or ensure_root or ensure_none.
decl_error! {
enum Error {
MyCustomError,
RequireSignedOrigin,
RequireRootOrigin,
RequireNoOrigin,
}
}
A proposed short term fix is to have decl_error! automatically add the 3 error types from frame_system for every new pallet:
- RequireSignedOrigin
- RequireRootOrigin
- RequireNoOrigin
Then to simply implement From between frame_system and the custom pallet being created.
At that point, the errors and UI should work as expected.
Long term, the solution here may need to be more robust and allow for verbose error tracing across multiple modules.
@thiolliere @bkchr