2021-12-12 17:10:40 +00:00
|
|
|
use std::{io, path::PathBuf};
|
2021-10-26 11:28:10 +00:00
|
|
|
use thiserror::Error;
|
|
|
|
|
|
|
|
pub type Result<T> = std::result::Result<T, SolcError>;
|
|
|
|
|
|
|
|
/// Various error types
|
|
|
|
#[derive(Debug, Error)]
|
|
|
|
pub enum SolcError {
|
|
|
|
/// Internal solc error
|
|
|
|
#[error("Solc Error: {0}")]
|
|
|
|
SolcError(String),
|
2021-12-04 17:13:58 +00:00
|
|
|
#[error("Missing pragma from solidity file")]
|
2021-11-03 08:05:09 +00:00
|
|
|
PragmaNotFound,
|
2021-12-04 17:13:58 +00:00
|
|
|
#[error("Could not find solc version locally or upstream")]
|
2021-11-03 08:05:09 +00:00
|
|
|
VersionNotFound,
|
2021-12-04 17:13:58 +00:00
|
|
|
#[error("Checksum mismatch")]
|
2021-11-26 10:30:14 +00:00
|
|
|
ChecksumMismatch,
|
2021-10-26 11:28:10 +00:00
|
|
|
#[error(transparent)]
|
|
|
|
SemverError(#[from] semver::Error),
|
|
|
|
/// Deserialization error
|
|
|
|
#[error(transparent)]
|
|
|
|
SerdeJson(#[from] serde_json::Error),
|
2021-12-04 17:13:58 +00:00
|
|
|
/// Filesystem IO error
|
2021-10-26 11:28:10 +00:00
|
|
|
#[error(transparent)]
|
2021-12-12 17:10:40 +00:00
|
|
|
Io(#[from] SolcIoError),
|
2022-02-10 17:56:25 +00:00
|
|
|
/// Failed to resolve a file
|
|
|
|
#[error("Failed to resolve file: {0}.\n Check configured remappings.")]
|
|
|
|
Resolve(SolcIoError),
|
2022-03-21 08:58:56 +00:00
|
|
|
#[cfg(feature = "svm-solc")]
|
2021-11-03 08:05:09 +00:00
|
|
|
#[error(transparent)]
|
|
|
|
SvmError(#[from] svm::SolcVmError),
|
2021-12-04 17:13:58 +00:00
|
|
|
#[error("No contracts found at \"{0}\"")]
|
2021-11-13 19:31:55 +00:00
|
|
|
NoContracts(String),
|
|
|
|
#[error(transparent)]
|
|
|
|
PatternError(#[from] glob::PatternError),
|
2021-12-11 17:39:39 +00:00
|
|
|
/// General purpose message
|
|
|
|
#[error("{0}")]
|
|
|
|
Message(String),
|
2021-12-12 23:39:28 +00:00
|
|
|
|
2022-02-04 16:20:24 +00:00
|
|
|
#[error("No artifact found for `{}:{}`", .0.display(), .1)]
|
|
|
|
ArtifactNotFound(PathBuf, String),
|
|
|
|
|
2021-12-12 23:39:28 +00:00
|
|
|
#[cfg(feature = "project-util")]
|
|
|
|
#[error(transparent)]
|
|
|
|
FsExtra(#[from] fs_extra::error::Error),
|
2021-10-26 11:28:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl SolcError {
|
2021-12-12 17:10:40 +00:00
|
|
|
pub(crate) fn io(err: io::Error, path: impl Into<PathBuf>) -> Self {
|
|
|
|
SolcIoError::new(err, path).into()
|
|
|
|
}
|
2021-10-26 11:28:10 +00:00
|
|
|
pub(crate) fn solc(msg: impl Into<String>) -> Self {
|
|
|
|
SolcError::SolcError(msg.into())
|
|
|
|
}
|
2022-01-20 19:41:19 +00:00
|
|
|
pub fn msg(msg: impl Into<String>) -> Self {
|
2021-12-11 17:39:39 +00:00
|
|
|
SolcError::Message(msg.into())
|
|
|
|
}
|
2021-10-26 11:28:10 +00:00
|
|
|
}
|
2021-12-12 17:10:40 +00:00
|
|
|
|
2022-03-15 12:27:49 +00:00
|
|
|
macro_rules! _format_err {
|
|
|
|
($($tt:tt)*) => {
|
|
|
|
$crate::error::SolcError::msg(format!($($tt)*))
|
|
|
|
};
|
|
|
|
}
|
|
|
|
#[allow(unused)]
|
|
|
|
pub(crate) use _format_err as format_err;
|
|
|
|
|
|
|
|
macro_rules! _bail {
|
|
|
|
($($tt:tt)*) => { return Err($crate::error::format_err!($($tt)*)) };
|
|
|
|
}
|
|
|
|
#[allow(unused)]
|
|
|
|
pub(crate) use _bail as bail;
|
|
|
|
|
2021-12-12 17:10:40 +00:00
|
|
|
#[derive(Debug, Error)]
|
|
|
|
#[error("\"{}\": {io}", self.path.display())]
|
|
|
|
pub struct SolcIoError {
|
|
|
|
io: io::Error,
|
|
|
|
path: PathBuf,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl SolcIoError {
|
|
|
|
pub fn new(io: io::Error, path: impl Into<PathBuf>) -> Self {
|
|
|
|
Self { io, path: path.into() }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<SolcIoError> for io::Error {
|
|
|
|
fn from(err: SolcIoError) -> Self {
|
|
|
|
err.io
|
|
|
|
}
|
|
|
|
}
|