ac_node_api/error/
mod.rs

1// This file was taken from subxt (Parity Technologies (UK))
2// https://github.com/paritytech/subxt/
3// And was adapted by Supercomputing Systems AG.
4//
5// Copyright 2019-2022 Parity Technologies (UK) Ltd, Supercomputing Systems AG.
6// This file is licensed as Apache-2.0
7// see LICENSE for license details.
8
9//! General node-api Error implementation.
10
11use alloc::{boxed::Box, string::String, vec::Vec};
12use core::fmt::Debug;
13use derive_more::From;
14
15// Re-expose the errors we use from other crates here:
16pub use crate::metadata::{MetadataConversionError, MetadataError};
17pub use scale_decode::{visitor::DecodeError as VisitorDecodeError, Error as DecodeError};
18pub use scale_encode::Error as EncodeError;
19pub use sp_core::crypto::SecretStringError;
20pub use sp_runtime::transaction_validity::TransactionValidityError;
21
22mod dispatch_error;
23pub use dispatch_error::*;
24
25/// The underlying error enum, generic over the type held by the `Runtime`
26/// variant. Prefer to use the [`Error<E>`] and [`Error`] aliases over
27/// using this type directly.
28#[derive(Debug, From)]
29pub enum Error {
30	/// Codec error.
31	Codec(codec::Error),
32	/// Serde serialization error
33	Serialization(serde_json::error::Error),
34	/// Secret string error.
35	SecretString(SecretStringError),
36	/// Invalid metadata error
37	InvalidMetadata(MetadataConversionError),
38	/// Invalid metadata error
39	Metadata(MetadataError),
40	/// Runtime error.
41	Runtime(DispatchError),
42	/// Error decoding to a [`crate::dynamic::Value`].
43	DecodeValue(Box<DecodeError>),
44	/// Error encoding from a [`crate::dynamic::Value`].
45	EncodeValue(Box<EncodeError>),
46	/// Visitor Decode Error.
47	Visitor(VisitorDecodeError),
48	/// The bytes representing an error that we were unable to decode.
49	Unknown(Vec<u8>),
50	/// Other error.
51	Other(String),
52}
53
54impl From<&str> for Error {
55	fn from(error: &str) -> Self {
56		Error::Other(error.into())
57	}
58}
59
60impl From<DecodeError> for Error {
61	fn from(error: DecodeError) -> Self {
62		Error::DecodeValue(Box::new(error))
63	}
64}
65
66impl From<EncodeError> for Error {
67	fn from(error: EncodeError) -> Self {
68		Error::EncodeValue(Box::new(error))
69	}
70}