Skip to content

Commit

Permalink
Workaround for pallet missing declare error type
Browse files Browse the repository at this point in the history
  • Loading branch information
jasl committed Apr 1, 2021
1 parent 1a8e0bc commit c355ad0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
22 changes: 17 additions & 5 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ pub enum RuntimeError {
/// Module error.
#[error("Runtime module error: {0}")]
Module(ModuleError),
/// Module error and the error is not found in metadata.
#[error("Runtime module error (missing metadata): {0}")]
ModuleMissingMetadata(ModuleError),
/// At least one consumer is remaining so the account cannot be destroyed.
#[error("At least one consumer is remaining so the account cannot be destroyed.")]
ConsumerRemaining,
Expand Down Expand Up @@ -129,11 +132,20 @@ impl RuntimeError {
message: _,
} => {
let module = metadata.module_with_errors(index)?;
let error = module.error(error)?;
Ok(Self::Module(ModuleError {
module: module.name().to_string(),
error: error.to_string(),
}))
match module.error(error) {
Ok(e) => {
Ok(Self::Module(ModuleError {
module: module.name().to_string(),
error: e.to_string(),
}))
},
Err(e) => {
Ok(Self::ModuleMissingMetadata(ModuleError {
module: module.name().to_string(),
error: e.to_string(),
}))
}
}
}
DispatchError::BadOrigin => Ok(Self::BadOrigin),
DispatchError::CannotLookup => Ok(Self::CannotLookup),
Expand Down
2 changes: 1 addition & 1 deletion src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub enum MetadataError {
/// Event is not in metadata.
#[error("Event {0} not found")]
EventNotFound(u8),
/// Event is not in metadata.
/// Error is not in metadata.
#[error("Error {0} not found")]
ErrorNotFound(u8),
/// Storage is not in metadata.
Expand Down

0 comments on commit c355ad0

Please sign in to comment.