emerald_vault/convert/
error.rs

1use std::fmt::Display;
2
3#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq, Display)]
4pub enum ConversionError {
5    InvalidArgument,
6    InvalidLength,
7    InvalidJson,
8    /// Value is the field name
9    InvalidFieldValue(String),
10    /// value is the field name
11    FieldIsEmpty(String),
12    /// value  is the field name
13    UnsupportedValue(String),
14    UnsupportedVersion,
15    UnsupportedFormat,
16    InvalidHex,
17    InvalidBase58,
18    CSVError,
19    InvalidProtobuf,
20    IOError,
21    OtherError,
22}
23
24impl From<serde_json::Error> for ConversionError {
25    fn from(_: serde_json::Error) -> Self {
26        ConversionError::InvalidJson
27    }
28}
29
30impl From<hex::FromHexError> for ConversionError {
31    fn from(_: hex::FromHexError) -> Self {
32        ConversionError::InvalidHex
33    }
34}
35
36impl From<protobuf::ProtobufError> for ConversionError {
37    fn from(err: protobuf::ProtobufError) -> Self {
38        match err {
39            protobuf::ProtobufError::IoError(_) => ConversionError::IOError,
40            _ => ConversionError::InvalidProtobuf,
41        }
42    }
43}
44
45impl From<std::convert::Infallible> for ConversionError {
46    fn from(_: std::convert::Infallible) -> Self {
47        ConversionError::OtherError
48    }
49}