From f4eb4029b49fde66665dac71b370efaea3f72876 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Sat, 23 Apr 2022 10:41:13 +0200 Subject: [PATCH] chore(solc): include error code in diagnostic (#1171) --- ethers-solc/src/artifacts/mod.rs | 14 ++++++++++++-- ethers-solc/src/compile/output.rs | 2 ++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/ethers-solc/src/artifacts/mod.rs b/ethers-solc/src/artifacts/mod.rs index 74aba89b..c15b78ce 100644 --- a/ethers-solc/src/artifacts/mod.rs +++ b/ethers-solc/src/artifacts/mod.rs @@ -1281,8 +1281,18 @@ impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { if let Some(msg) = &self.formatted_message { match self.severity { - Severity::Error => msg.as_str().red().fmt(f), - Severity::Warning | Severity::Info => msg.as_str().yellow().fmt(f), + Severity::Error => { + if let Some(code) = self.error_code { + format!("error[{}]: ", code).as_str().red().fmt(f)?; + } + msg.as_str().red().fmt(f) + } + Severity::Warning | Severity::Info => { + if let Some(code) = self.error_code { + format!("warning[{}]: ", code).as_str().yellow().fmt(f)?; + } + msg.as_str().yellow().fmt(f) + } } } else { self.severity.fmt(f)?; diff --git a/ethers-solc/src/compile/output.rs b/ethers-solc/src/compile/output.rs index 2ff3e08c..2ee3eddb 100644 --- a/ethers-solc/src/compile/output.rs +++ b/ethers-solc/src/compile/output.rs @@ -354,7 +354,9 @@ impl AggregatedCompilerOutput { /// Helper type to implement display for solc errors #[derive(Clone, Debug)] pub struct OutputDiagnostics<'a> { + /// output of the compiled project compiler_output: &'a AggregatedCompilerOutput, + /// the error codes to ignore ignored_error_codes: &'a [u64], }