Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Make decl_error! slightly more friendly for frame_system #4384

@shawntabrizi

Description

@shawntabrizi

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions