stylus_core/calls/
errors.rs1extern crate alloc;
5
6use alloc::vec::Vec;
7use alloy_sol_types::{Panic, PanicKind, SolError};
8
9#[derive(Debug, PartialEq)]
11pub enum Error {
12 Revert(Vec<u8>),
14 AbiDecodingFailed(alloy_sol_types::Error),
16}
17
18impl From<alloy_sol_types::Error> for Error {
19 fn from(err: alloy_sol_types::Error) -> Self {
20 Error::AbiDecodingFailed(err)
21 }
22}
23
24pub trait MethodError {
29 fn encode(self) -> Vec<u8>;
31}
32
33impl MethodError for Error {
34 #[inline]
35 fn encode(self) -> Vec<u8> {
36 From::from(self)
37 }
38}
39
40impl<T: SolError> MethodError for T {
41 #[inline]
42 fn encode(self) -> Vec<u8> {
43 SolError::abi_encode(&self)
44 }
45}
46
47impl From<Error> for Vec<u8> {
48 fn from(err: Error) -> Vec<u8> {
49 match err {
50 Error::Revert(data) => data,
51 #[allow(unused)]
52 Error::AbiDecodingFailed(err) => Panic::from(PanicKind::Generic).abi_encode(),
53 }
54 }
55}