ethcontract_common/
errors.rs

1//! Module with common error types.
2
3use serde_json::Error as JsonError;
4use std::io::Error as IoError;
5use thiserror::Error;
6
7/// An error in loading or parsing an artifact.
8#[derive(Debug, Error)]
9pub enum ArtifactError {
10    /// An IO error occurred when loading a truffle artifact from disk.
11    #[error("failed to open contract artifact file: {0}")]
12    Io(#[from] IoError),
13
14    /// A JSON error occurred while parsing a truffle artifact.
15    #[error("failed to parse contract artifact JSON: {0}")]
16    Json(#[from] JsonError),
17
18    /// Contract was deployed onto different chains, and ABIs don't match.
19    #[error("contract {0} has different ABIs on different chains")]
20    AbiMismatch(String),
21
22    /// Contract have multiple deployment addresses on the same chain.
23    #[error("chain with id {0} appears several times in the artifact")]
24    DuplicateChain(String),
25}
26
27/// An error reading bytecode string representation.
28#[derive(Debug, Error)]
29pub enum BytecodeError {
30    /// Bytecode string is not an even length.
31    #[error("invalid bytecode length")]
32    InvalidLength,
33
34    /// Placeholder is not long enough at end of bytecode string.
35    #[error("placeholder at end of bytecode is too short")]
36    PlaceholderTooShort,
37
38    /// Invalid hex digit
39    #[error("invalid hex digit '{0}'")]
40    InvalidHexDigit(char),
41}
42
43/// An error linking a library to bytecode.
44#[derive(Debug, Error)]
45pub enum LinkError {
46    /// Error when attempting to link a library when its placeholder cannot be
47    /// found.
48    #[error("unable to link library: can't find link placeholder for {0}")]
49    NotFound(String),
50
51    /// Error producing final bytecode binary when there are missing libraries
52    /// that are not linked. Analogous to "undefinied symbol" error for
53    /// traditional linkers.
54    #[error("undefined library {0}")]
55    UndefinedLibrary(String),
56}
57
58/// An error representing an error parsing a parameter type.
59#[derive(Clone, Debug, Error)]
60#[error("'{0}' is not a valid Solidity type")]
61pub struct ParseParamTypeError(pub String);