eth_valkyoth_protocol/transaction/encode/
error.rs1use core::fmt;
2
3use eth_valkyoth_codec::{DecodeError, DecodeErrorCategory};
4
5#[non_exhaustive]
7#[derive(Clone, Copy, Debug, Eq, PartialEq)]
8pub enum TransactionEncodeError {
9 Codec(DecodeError),
11}
12
13impl TransactionEncodeError {
14 #[must_use]
16 pub const fn code(self) -> &'static str {
17 match self {
18 Self::Codec(error) => error.code(),
19 }
20 }
21
22 #[must_use]
24 pub const fn message(self) -> &'static str {
25 match self {
26 Self::Codec(error) => error.message(),
27 }
28 }
29
30 #[must_use]
32 pub const fn category(self) -> TransactionEncodeErrorCategory {
33 match self {
34 Self::Codec(error) => match error.category() {
35 DecodeErrorCategory::MalformedInput => {
36 TransactionEncodeErrorCategory::MalformedInput
37 }
38 DecodeErrorCategory::ResourceExhaustion => {
39 TransactionEncodeErrorCategory::ResourceExhaustion
40 }
41 _ => TransactionEncodeErrorCategory::MalformedInput,
42 },
43 }
44 }
45}
46
47impl From<DecodeError> for TransactionEncodeError {
48 fn from(error: DecodeError) -> Self {
49 Self::Codec(error)
50 }
51}
52
53impl fmt::Display for TransactionEncodeError {
54 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
55 formatter.write_str(self.message())
56 }
57}
58
59#[cfg(feature = "std")]
60impl std::error::Error for TransactionEncodeError {}
61
62#[non_exhaustive]
64#[derive(Clone, Copy, Debug, Eq, PartialEq)]
65pub enum TransactionEncodeErrorCategory {
66 MalformedInput,
68 ResourceExhaustion,
70}