1use core::{
2 array::TryFromSliceError,
3 num::{ParseIntError, TryFromIntError},
4 str::Utf8Error,
5};
6use std::string::FromUtf8Error;
7
8use rapira::{EnumFromU8Error, RapiraError};
9#[cfg(feature = "std")]
10use thiserror::Error;
11use zerocopy::{TryFromBytes, error::ValidityError};
12
13#[cfg_attr(feature = "std", derive(Error, Debug))]
14pub enum ArmourError {
15 #[cfg_attr(feature = "std", error("from bytes error"))]
16 FromBytesError,
17 #[cfg_attr(feature = "std", error("bytes len error"))]
18 BytesLenError,
19 #[cfg_attr(feature = "std", error(transparent))]
20 TryFromSliceError(#[from] TryFromSliceError),
21 #[cfg_attr(feature = "std", error("NonZero is 0"))]
22 NonZeroError,
23 #[cfg_attr(feature = "std", error(transparent))]
24 NonZero(#[from] TryFromIntError),
25 #[cfg_attr(feature = "std", error(transparent))]
26 ParseInt(#[from] ParseIntError),
27 #[cfg_attr(feature = "std", error(transparent))]
28 RapiraError(#[from] RapiraError),
29 #[cfg_attr(feature = "std", error(transparent))]
30 EnumFromU8(#[from] EnumFromU8Error),
31 #[cfg_attr(feature = "std", error("zbase decode error"))]
32 ZBaseDecodeError,
33 #[cfg_attr(feature = "std", error("hex decode error"))]
34 HexDecodeError,
35 #[cfg_attr(feature = "std", error("unknown error"))]
36 UnknownError,
37 #[cfg_attr(feature = "std", error("hash index exist"))]
38 HashIndexExist,
39 #[cfg_attr(feature = "std", error("id decode error"))]
40 IdDecodeError,
41 #[cfg_attr(feature = "std", error("zerocopy validity error"))]
42 ZerocopyValidityError,
43 #[cfg_attr(feature = "std", error("utf8 decode error: {0}"))]
44 FromUtf8Error(#[from] FromUtf8Error),
45 #[cfg_attr(feature = "std", error("utf8 decode error: {0}"))]
46 Utf8Error(#[from] Utf8Error),
47}
48
49impl<S, D: TryFromBytes> From<ValidityError<S, D>> for ArmourError {
50 fn from(_: ValidityError<S, D>) -> Self {
51 ArmourError::ZerocopyValidityError
52 }
53}