zebra_chain/serialization/
error.rs1use std::{array::TryFromSliceError, io, num::TryFromIntError, str::Utf8Error, sync::Arc};
4
5use hex::FromHexError;
6use thiserror::Error;
7
8#[derive(Clone, Error, Debug)]
11pub enum SerializationError {
12 #[error("io error: {0}")]
14 Io(#[from] Arc<io::Error>),
15
16 #[error("parse error: {0}")]
19 Parse(&'static str),
20
21 #[error("string was not UTF-8: {0}")]
25 Utf8Error(#[from] Utf8Error),
26
27 #[error("slice was the wrong length: {0}")]
29 TryFromSliceError(#[from] TryFromSliceError),
30
31 #[error("CompactSize too large: {0}")]
33 TryFromIntError(#[from] TryFromIntError),
34
35 #[error("string was not hex: {0}")]
37 FromHexError(#[from] FromHexError),
38
39 #[error("input couldn't be parsed as a zatoshi `Amount`: {source}")]
41 Amount {
42 #[from]
44 source: crate::amount::Error,
45 },
46
47 #[error("transaction balance is non-zero but doesn't have Sapling shielded spends or outputs")]
52 BadTransactionBalance,
53}
54
55impl From<crate::Error> for SerializationError {
56 fn from(value: crate::Error) -> Self {
57 match value {
58 crate::Error::InvalidConsensusBranchId => Self::Parse("invalid consensus branch id"),
59 crate::Error::Conversion(e) => Self::Io(e),
60 crate::Error::MissingNetworkUpgrade => Self::Parse("missing network upgrade"),
61 }
62 }
63}
64
65impl From<io::Error> for SerializationError {
68 fn from(value: io::Error) -> Self {
69 Arc::new(value).into()
70 }
71}