chore(solc): include error code in diagnostic (#1171)

This commit is contained in:
Matthias Seitz 2022-04-23 10:41:13 +02:00 committed by GitHub
parent 1cba287193
commit f4eb4029b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

@ -1281,8 +1281,18 @@ impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Some(msg) = &self.formatted_message { if let Some(msg) = &self.formatted_message {
match self.severity { match self.severity {
Severity::Error => msg.as_str().red().fmt(f), Severity::Error => {
Severity::Warning | Severity::Info => msg.as_str().yellow().fmt(f), 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 { } else {
self.severity.fmt(f)?; self.severity.fmt(f)?;

View File

@ -354,7 +354,9 @@ impl AggregatedCompilerOutput {
/// Helper type to implement display for solc errors /// Helper type to implement display for solc errors
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct OutputDiagnostics<'a> { pub struct OutputDiagnostics<'a> {
/// output of the compiled project
compiler_output: &'a AggregatedCompilerOutput, compiler_output: &'a AggregatedCompilerOutput,
/// the error codes to ignore
ignored_error_codes: &'a [u64], ignored_error_codes: &'a [u64],
} }