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.

Allow nested pallet error, and encode pallet error in 2 bytes. #8081

@gui1117

Description

@gui1117

Currently pallet error is encoded in one byte, and declare in the metadata some documentation associated to each byte.

But we could encode the error on 2 bytes and allow some nested error. As long as the nested error encode in 1 byte and declare its metadata in some way.

We could implement something like this:

#[pallet::error]
enum Error<C: Config> {
    /// Some error
    Foo(Bar),
}

And require Bar to implement a trait.

trait PalletNestedError: Into<u8> {
    fn metadata() -> &[&'static str];
}

The nested error could make use of regular derive macro.

#[derive(PalletNestedError)]
pub enum Bar {
    /// Some doc
    M,
}

This require also some changes in the metadata, (and we probably want to keep the old metadata format available for off-chain libraries, but this is another issue #8083).

Metadata

Metadata

Assignees

Labels

J0-enhancementAn additional feature request.Z2-mediumCan be fixed by a coder with good Rust knowledge but little knowledge of the codebase.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions