tycho_simulation/protocol/
errors.rs1use std::io;
3
4use serde_json::Error as SerdeError;
5use thiserror::Error;
6use tycho_common::{hex_bytes::IntegerFromBytesError, simulation::errors::SimulationError};
7
8#[derive(Debug, Error)]
9pub enum InvalidSnapshotError {
10 #[error("Missing attributes {0}")]
11 MissingAttribute(String),
12 #[error("Value error {0}")]
13 ValueError(String),
14 #[error("Unable to set up vm state on the engine: {0}")]
15 VMError(SimulationError),
16}
17
18impl From<SimulationError> for InvalidSnapshotError {
19 fn from(error: SimulationError) -> Self {
20 InvalidSnapshotError::VMError(error)
21 }
22}
23
24impl From<IntegerFromBytesError> for InvalidSnapshotError {
25 fn from(error: IntegerFromBytesError) -> Self {
26 InvalidSnapshotError::ValueError(error.to_string())
27 }
28}
29
30impl From<FileError> for SimulationError {
31 fn from(error: FileError) -> Self {
32 SimulationError::FatalError(error.to_string())
33 }
34}
35
36#[derive(Debug, Error)]
37pub enum FileError {
38 #[error("Malformed ABI error: {0}")]
40 MalformedABI(String),
41 #[error("Structure error {0}")]
43 Structure(String),
44 #[error("File path conversion error {0}")]
46 FilePath(String),
47 #[error("I/O error {0}")]
48 Io(io::Error),
49 #[error("Json parsing error {0}")]
50 Parse(SerdeError),
51}
52
53impl From<io::Error> for FileError {
54 fn from(err: io::Error) -> Self {
55 FileError::Io(err)
56 }
57}
58
59impl From<SerdeError> for FileError {
60 fn from(err: SerdeError) -> Self {
61 FileError::Parse(err)
62 }
63}