1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use thiserror::Error;

#[derive(Error, Debug)]
pub enum Error {
  #[error("Std io error: {0}")]
  StdIo(#[from] std::io::Error),

  #[error("Json error: {0}")]
  Json(#[from] serde_json::Error),

  #[error("hex error: {0}")]
  Hex(#[from] hex::FromHexError),

  #[error("http error: {0}")]
  Http(#[from] http::Error),

  #[error("http uri error: {0}")]
  HttpUri(#[from] http::uri::InvalidUri),

  #[error("parity-scale-codec error: {0}")]
  ParityScaleCodec(#[from] codec::Error),

  #[error("sp-core crypto secret error: {0}")]
  SecretStringError(String),

  #[error("Call API incompatible with connected chain: {0}")]
  IncompatibleCall(String),

  #[error("Schema failed to parse: {0}")]
  SchemaParseFailed(String),

  #[error("Metadata failed to parse: {0}")]
  MetadataParseFailed(String),

  #[error("ExtrinsicError: {0}")]
  ExtrinsicError(String),

  #[error("RpcClient: {0}")]
  RpcClient(String),

  #[error("Decode type failed: {0}")]
  DecodeTypeFailed(String),

  #[error("Signing transaction failed: {0}")]
  SigningTransactionFailed(String),

  #[error("Jsonrpsee error: {0}")]
  Jsonrpsee(#[from] jsonrpsee::core::Error),
}

impl From<sp_core::crypto::SecretStringError> for Error {
  fn from(e: sp_core::crypto::SecretStringError) -> Self {
    Self::SecretStringError(format!("{e:?}"))
  }
}

pub type Result<T, E = Error> = std::result::Result<T, E>;