shuttle_core/
error.rs

1use std::result;
2use std::convert::From;
3use std::str;
4use base64;
5use bigdecimal;
6use serde_xdr;
7
8/// The Errors that can occur.
9#[derive(Debug)]
10pub enum Error {
11    /// Error that can occur when parsing a key.
12    InvalidStrKey,
13    /// Invalid version byte in key.
14    InvalidStrKeyVersionByte,
15    /// Invalid checksum in key.
16    InvalidStrKeyChecksum,
17    /// Invalid keypair seed.
18    InvalidSeed,
19    /// Invalid Asset code.
20    InvalidAssetCode,
21    /// Invalid signature.
22    InvalidSignature,
23    /// Invalid memo text: too long.
24    InvalidMemoText,
25    /// Error that can occur when parsing amounts from stroops.
26    InvalidStroopsAmount,
27    /// Error that can occur when converting an amount with more than 7 digits.
28    InvalidAmountScale,
29    /// Invalid network id: too long.
30    InvalidNetworkId,
31    /// Invalid public key.
32    InvalidPublicKey,
33    /// Error that can occur when interpreting a sequence of `u8` as utf-8.
34    Utf8Error(str::Utf8Error),
35    /// Error that can occour when decoding base64 encoded data.
36    DecodeError(base64::DecodeError),
37    /// Error that can occur when parsing amounts.
38    ParseAmountError(bigdecimal::ParseBigDecimalError),
39    /// Error that can occur when serializing to XDR.
40    SerializationError(serde_xdr::CompatSerializationError),
41    /// Error that can occur when deserializing from XDR.
42    DeserializationError(serde_xdr::CompatDeserializationError),
43}
44
45/// A `Result` alias where `Error` is a `shuttle_core::Error`.
46pub type Result<T> = result::Result<T, Error>;
47
48impl From<str::Utf8Error> for Error {
49    fn from(err: str::Utf8Error) -> Self {
50        Error::Utf8Error(err)
51    }
52}
53
54impl From<base64::DecodeError> for Error {
55    fn from(err: base64::DecodeError) -> Self {
56        Error::DecodeError(err)
57    }
58}
59
60impl From<bigdecimal::ParseBigDecimalError> for Error {
61    fn from(err: bigdecimal::ParseBigDecimalError) -> Self {
62        Error::ParseAmountError(err)
63    }
64}
65
66impl From<serde_xdr::CompatDeserializationError> for Error {
67    fn from(err: serde_xdr::CompatDeserializationError) -> Self {
68        Error::DeserializationError(err)
69    }
70}
71
72impl From<serde_xdr::CompatSerializationError> for Error {
73    fn from(err: serde_xdr::CompatSerializationError) -> Self {
74        Error::SerializationError(err)
75    }
76}