substrate_constructor/
error.rs1use external_memory_tools::ExternalMemory;
2use std::fmt::{Debug, Display, Formatter, Result as FmtResult};
3use substrate_parser::{
4 error::{ExtensionsError, RegistryError},
5 traits::AsMetadata,
6};
7
8#[derive(Debug)]
9pub enum ErrorFixMe<E: ExternalMemory, M: AsMetadata<E>> {
10 ExtensionsList(ExtensionsError),
11 ExtraNotInExtensions,
12 MetaStructure(M::MetaStructureError),
13 Registry(RegistryError<E>),
14 UnfinalizedExtension,
15 WrongExtraStructure,
16}
17
18#[derive(Debug)]
19pub enum StorageRegistryError {
20 MapHashesNotATuple,
21 MapHashesNumberMismatch,
22}
23
24impl StorageRegistryError {
25 fn error_text(&self) -> String {
26 match self {
27 StorageRegistryError::MapHashesNotATuple => String::from("Unexpected storage structure in metadata. `StorageEntryType::Map { .. }` must have either a single describing type, or a set of types in tuple format."),
28 StorageRegistryError::MapHashesNumberMismatch => String::from("Unexpected storage structure in metadata. `StorageEntryType::Map { .. }` has different number of hashers in hasher set and types in descriptor."),
29 }
30 }
31}
32
33impl Display for StorageRegistryError {
34 fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
35 write!(f, "{}", self.error_text())
36 }
37}
38
39impl<E: ExternalMemory, M: AsMetadata<E>> ErrorFixMe<E, M> {
40 fn error_text(&self) -> String {
41 match self {
42 ErrorFixMe::ExtensionsList(extensions_error) => format!("Unexpected extensions structure in metadata. {extensions_error}"),
43 ErrorFixMe::ExtraNotInExtensions => String::from("Unexpected metadata structure. Data required to build a technical part of a sendable transaction (`extra`) is not a part of extensions set."),
44 ErrorFixMe::MetaStructure(meta_structure_error) => format!("Unexpected metadata structure. {meta_structure_error}"),
45 ErrorFixMe::Registry(registry_error) => format!("Error in metadata types registry. {}", registry_error),
46 ErrorFixMe::UnfinalizedExtension => String::from("Unable to sign uncheched extrinsic, as some of the extensions are not completed."),
47 ErrorFixMe::WrongExtraStructure => String::from("Unexpected metadata structure. Extra set is expected to be either a struct or a tuple, and apparently is neither."),
48 }
49 }
50}
51
52impl<E: ExternalMemory, M: AsMetadata<E>> Display for ErrorFixMe<E, M> {
53 fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
54 write!(f, "{}", self.error_text())
55 }
56}
57
58impl<E: ExternalMemory, M: AsMetadata<E>> std::error::Error for ErrorFixMe<E, M> {}
59
60impl std::error::Error for StorageRegistryError {}
61
62impl<E: ExternalMemory, M: AsMetadata<E>> From<RegistryError<E>> for ErrorFixMe<E, M> {
63 fn from(registry_error: RegistryError<E>) -> Self {
64 ErrorFixMe::Registry(registry_error)
65 }
66}