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(thiserror::Error, Debug)]
14#[non_exhaustive]
15pub enum Error {
16    /// Solidity version is not supported
17    #[error("the provided Solidity version is not supported: `{0}`")]
18    SolidityUnsupportedVersion(String),
19
20    #[error("there was an error while parsing {path}:{loc}:\n{message}")]
21    ParsingError {
22        path: PathBuf,
23        loc: TextIndex,
24        message: String,
25    },
26
27    /// Error during parsing of a version specifier string
28    #[error("error parsing a semver string: {0}")]
29    SemverParsingError(#[from] semver::Error),
30
31    /// Error during parsing of a `NatSpec` comment
32    #[error("error parsing a natspec comment: {message}")]
33    NatspecParsingError {
34        parent: Option<Parent>,
35        span: TextRange,
36        message: String,
37    },
38
39    /// [`Parse::get_sources`][crate::parser::Parse::get_sources] was called while other references (clones) still
40    /// existed
41    #[error("`Parse::get_sources` can only be called on the last parser instance")]
42    DanglingParserReferences,
43
44    /// IO error
45    #[error("IO error for {path:?}: {err}")]
46    IOError { path: PathBuf, err: std::io::Error },
47
48    /// An unspecified error happening during parsing
49    #[error("unknown error while parsing Solidity")]
50    UnknownError,
51}