ethers-rs/ethers-solc/src/error.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

116 lines
3.2 KiB
Rust
Raw Normal View History

use semver::Version;
use std::{
io,
path::{Path, PathBuf},
};
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),
#[error("Missing pragma from solidity file")]
PragmaNotFound,
#[error("Could not find solc version locally or upstream")]
VersionNotFound,
#[error("Checksum mismatch for {file}: expected {expected} found {detected} for {version}")]
ChecksumMismatch { version: Version, expected: String, detected: String, file: PathBuf },
#[error(transparent)]
SemverError(#[from] semver::Error),
/// Deserialization error
#[error(transparent)]
SerdeJson(#[from] serde_json::Error),
/// Filesystem IO error
#[error(transparent)]
Io(#[from] SolcIoError),
#[error("File could not be resolved due to broken symlink: {0}.")]
ResolveBadSymlink(SolcIoError),
/// Failed to resolve a file
#[error("Failed to resolve file: {0}.\n Check configured remappings.")]
Resolve(SolcIoError),
#[error("File cannot be resolved due to mismatch of file name case: {error}.\n Found existing file: {existing_file:?}\n Please check the case of the import.")]
ResolveCaseSensitiveFileName { error: SolcIoError, existing_file: PathBuf },
#[error(
r#"{0}.
--> {1:?}
{2:?}"#
)]
FailedResolveImport(Box<SolcError>, PathBuf, PathBuf),
#[cfg(all(feature = "svm-solc", not(target_arch = "wasm32")))]
#[error(transparent)]
SvmError(#[from] svm::SolcVmError),
#[error("No contracts found at \"{0}\"")]
NoContracts(String),
#[error(transparent)]
PatternError(#[from] glob::PatternError),
/// General purpose message
#[error("{0}")]
Message(String),
refactor(solc): rewrite compiler passes and cache change detection (#802) * chore: clippy * refactor: rewrite compiler passes and cache * feat: more work on compile pipeline * feat: add cache constructor * add artifact filtering * fine tune api * feat: prepare version integration * docs: more docs * feat: add cacheentry2 * replace cacheentry types * integrate new api * docs: more docs * feat: implement new output handler * feat: integrate cached files in new compile pipeline * refactor: more cache refactor * docs: more docs * feat: add source name mapping * feat: implement new parallel solc * refactor: do a little cleanup * refactor: even more cleanup * even more cleanup * chore: make it compile * chore: make it compile with all features * chore: clippy fix * feat: integrate new compiler pipeline * docs: more docs * refactor: move stuff around * refactor: start deprecating output type * chore: make it compile again * chore(deps): bump solc version 0.2.0 * feat: unify output types * cargo fix * refactor: add contracts wrapper * chore: replace ProjectCompileOutput * docs: add more docs * feat: add offline mode * feat: more artifact helpers * chore: cleanup cache * chore: streamline types * fix: better artifacts mapping * chore: some cleanup * chore: change artifact * chore: add configure solc fn * feat: add artifact reading * feat: implement retain and extend * feat: add cache extending * feat: write to disk * chore: make clippy happy * feat: implement path mapping * chore: nits * feat: introduce states * feat: add compiler state machine * chore: move cache types to cache mod * chore: make clippy happy * feat: add debug derives * fix: use resolved import source unit names * fix: failing tests * test: test multiple libs properly * chore: make clippy happy * chore: update CHANGELOG * fix: doc tests * fix: set offline mode correctly * chore: make it compile again * Update ethers-solc/src/artifacts.rs Co-authored-by: Georgios Konstantopoulos <me@gakonst.com> * feat: find remappings by default * typos * add eth_syncing RPC (#848) * add eth_syncing RPC * Changelo updated * small comments * Intermediate SyncingStatus * fix(core): adjust Ganache for new cli output (#851) * fix: review comments * fix: cache relative path bug * chore: add cache example * chore: use absolute paths * fix: remove overwritten files from cache * fix: rustfmt * chore: more helper functions * chore: export AggregatedOutput * feat: implement helper functions * feat: even more helpers * fix: failing doc tests * refactor: remove source name map tracking * fix: determine artifacts in ephemeral mode * refactor: allowed paths should not fail Co-authored-by: Georgios Konstantopoulos <me@gakonst.com> Co-authored-by: rakita <rakita@users.noreply.github.com> Co-authored-by: wolflo <33909953+wolflo@users.noreply.github.com>
2022-02-04 16:20:24 +00:00
#[error("No artifact found for `{}:{}`", .0.display(), .1)]
ArtifactNotFound(PathBuf, String),
#[cfg(feature = "project-util")]
#[error(transparent)]
FsExtra(#[from] fs_extra::error::Error),
}
impl SolcError {
pub(crate) fn io(err: io::Error, path: impl Into<PathBuf>) -> Self {
SolcIoError::new(err, path).into()
}
pub(crate) fn solc(msg: impl Into<String>) -> Self {
SolcError::SolcError(msg.into())
}
pub fn msg(msg: impl Into<String>) -> Self {
SolcError::Message(msg.into())
}
}
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;
#[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() }
}
/// The path at which the error occurred
pub fn path(&self) -> &Path {
&self.path
}
/// The underlying `io::Error`
pub fn source(&self) -> &io::Error {
&self.io
}
}
impl From<SolcIoError> for io::Error {
fn from(err: SolcIoError) -> Self {
err.io
}
}