1#[derive(thiserror::Error, Debug)]
3#[error(transparent)]
4pub struct Error {
5 kind: Box<ErrorKind>,
6}
7
8impl Error {
9 pub fn new(kind: ErrorKind) -> Self {
11 kind.into()
12 }
13
14 pub fn parse(err: wasmparser::BinaryReaderError) -> Self {
16 err.into()
17 }
18
19 pub fn no_mutations_applicable() -> Self {
21 ErrorKind::NoMutationsApplicable.into()
22 }
23
24 pub fn out_of_fuel() -> Self {
26 ErrorKind::OutOfFuel.into()
27 }
28
29 pub fn unsupported(msg: impl Into<String>) -> Self {
31 ErrorKind::Unsupported(msg.into()).into()
32 }
33
34 pub fn other(err: impl Into<String>) -> Self {
36 ErrorKind::Other(err.into()).into()
37 }
38
39 pub fn kind(&self) -> &ErrorKind {
41 &*self.kind
42 }
43}
44
45impl From<ErrorKind> for Error {
46 fn from(kind: ErrorKind) -> Self {
47 Error {
48 kind: Box::new(kind),
49 }
50 }
51}
52
53impl From<wasmparser::BinaryReaderError> for Error {
54 fn from(e: wasmparser::BinaryReaderError) -> Self {
55 ErrorKind::Parse(e).into()
56 }
57}
58
59impl<E> From<wasm_encoder::reencode::Error<E>> for Error
60where
61 E: Into<Error> + std::fmt::Display,
62{
63 fn from(e: wasm_encoder::reencode::Error<E>) -> Self {
64 match e {
65 wasm_encoder::reencode::Error::ParseError(e) => Error::parse(e),
66 wasm_encoder::reencode::Error::UserError(e) => e.into(),
67 other => Error::other(other.to_string()),
68 }
69 }
70}
71
72impl From<std::convert::Infallible> for Error {
73 fn from(i: std::convert::Infallible) -> Error {
74 match i {}
75 }
76}
77
78#[derive(thiserror::Error, Debug)]
80pub enum ErrorKind {
81 #[error("Failed to parse the input Wasm module.")]
83 Parse(#[from] wasmparser::BinaryReaderError),
84
85 #[error("There are not applicable mutations for the input Wasm module.")]
87 NoMutationsApplicable,
88
89 #[error("Out of fuel")]
91 OutOfFuel,
92
93 #[error("Unsupported: {0}")]
95 Unsupported(String),
96
97 #[error("{0}")]
99 Other(String),
100}
101
102pub type Result<T, E = Error> = std::result::Result<T, E>;
104
105pub type ReencodeResult<T, E = Error> = Result<T, wasm_encoder::reencode::Error<E>>;