Skip to main content

huff_neo_test_runner/
errors.rs

1use huff_neo_utils::ast::span::AstSpan;
2use huff_neo_utils::error::{CodegenError, CompilerError};
3use revm::context::result::EVMError;
4use std::convert::Infallible;
5use thiserror::Error;
6
7/// A Runner error
8#[derive(Debug, Error)]
9pub enum RunnerError {
10    #[error("Runner Error: {0}")]
11    GenericError(String),
12
13    #[error("Deployment Error: {0}")]
14    DeploymentError(String),
15
16    #[error("Invalid {0}: {1}")]
17    InvalidHex(&'static str, String),
18
19    #[error("{0}")]
20    InvalidDecorator(DecoratorError),
21
22    #[error("Compiler Error: {0}")]
23    CompilerError(CompilerError),
24
25    #[error("Evm transact error with err={0}")]
26    TransactError(String),
27
28    #[error(transparent)]
29    EVMError(#[from] EVMError<Infallible>),
30
31    #[error(transparent)]
32    EVMErrorDB(#[from] EVMError<foundry_evm::backend::DatabaseError>),
33}
34
35impl From<CodegenError> for RunnerError {
36    fn from(error: CodegenError) -> Self {
37        RunnerError::CompilerError(CompilerError::CodegenError(error))
38    }
39}
40
41/// The ways a decorator flag can be invalid for the test runner
42#[derive(Debug, Clone, PartialEq, Eq)]
43pub enum DecoratorErrorKind {
44    /// The flag name is not a known decorator
45    UnknownFlag,
46    /// The flag has the wrong number of arguments, or an unknown or repeated `key =` argument
47    InvalidArguments,
48    /// An argument value has the wrong type or cannot be evaluated
49    InvalidValue,
50    /// A single-use flag is repeated, or a storage slot is set twice
51    Duplicate,
52    /// The flag contradicts another flag, such as two ways for the test to end
53    Conflict,
54}
55
56/// A decorator flag the test runner cannot apply, pointing at the offending source
57#[derive(Debug, Clone, PartialEq, Eq, Error)]
58#[error("Invalid Decorator Flag: \"{flag}\"\n{}", span.error(Some(hint)))]
59pub struct DecoratorError {
60    /// The flag name
61    pub flag: String,
62    /// What is wrong with the flag
63    pub kind: DecoratorErrorKind,
64    /// How to fix the flag
65    pub hint: String,
66    /// The flag or argument, or both places for a duplicate
67    pub span: AstSpan,
68}