Skip to main content

lintspec_core/
error.rs

1//! The error and result types for lintspec
2use std::path::PathBuf;
3
4use crate::{
5    definitions::Parent,
6    textindex::{TextIndex, TextRange},
7};
8
9/// The result of a lintspec operation
10pub type Result<T> = std::result::Result<T, Error>;
11
12/// A lintspec error
13#[derive(Debug, thiserror::Error, thiserror_ext::Box)]
14#[thiserror_ext(newtype(name = Error))]
15#[non_exhaustive]
16pub enum ErrorKind {
17    /// Solidity version is not supported
18    #[error("the provided Solidity version is not supported: `{0}`")]
19    SolidityUnsupportedVersion(String),
20
21    #[error("there was an error while parsing {path}:{loc}:\n{message}")]
22    ParsingError {
23        path: PathBuf,
24        loc: TextIndex,
25        message: String,
26    },
27
28    /// Error during parsing of a version specifier string
29    #[error("error parsing a semver string: {0}")]
30    SemverParsingError(#[from] semver::Error),
31
32    /// Error during parsing of a `NatSpec` comment
33    #[error("error parsing a natspec comment: {message}")]
34    NatspecParsingError {
35        parent: Option<Parent>,
36        span: TextRange,
37        message: String,
38    },
39
40    /// [`Parse::get_sources`][crate::parser::Parse::get_sources] was called while other references (clones) still
41    /// existed
42    #[error("`Parse::get_sources` can only be called on the last parser instance")]
43    DanglingParserReferences,
44
45    /// IO error
46    #[error("IO error for {path:?}: {err}")]
47    IOError { path: PathBuf, err: std::io::Error },
48
49    /// An unspecified error happening during parsing
50    #[error("unknown error while parsing Solidity")]
51    UnknownError,
52}