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).