2

I want to add custom error types to a working pallet (permalink duniter-wot/src/lib.rs). In this current state, cargo check pass successfully.

According to Substrate documentation frame-macros/#palleterror, I'm adding inside the #[frame_support::pallet] block a #[pallet::error] macro with an enumeration named Error with a generic type like:

#[pallet::error]
pub enum Error<T> {
    /// variant one
    VariantOne,
    /// variant two
    VariantTwo,
}

But as soon as I do this, cargo check returns a long (> 700 lines) error trace in which the first element is:

error: Invalid generic declaration, trait is defined with instance but generic use none
  --> pallets/duniter-wot/src/lib.rs:99:20
   |
99 |     pub enum Error<T> {
   |                    ^

The question, more than "how to fix this" would be "how am I supposed to understand this hint" and "what resources/tools/documentation could help me debug myself".

1 Answer 1

2

It looks like your pallet is instantiatable. This requires you to additionally pass in the instance type like such. In the easiest case it looks like this:

#[pallet::error]
pub enum Error<T, I = ()> {

Making a pallet instantiatable is useful when you plan on having more than one instance deployed within the same runtime.

what resources/tools/documentation could help me debug myself

For me personally it is enough to read examples from the Substrate repo. For example pallet-referenda.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.