Display error codes better.
This is a *slight* hack / abuse of the code() method as we are now doing a bit of formatting within that function. Yet, we only do so at the very top-level (i.e. project's Error) because we can't actually fiddle with how miette presents errors.
This commit is contained in:
parent
6c039708c3
commit
7645a9460f
|
@ -262,31 +262,45 @@ impl Diagnostic for Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn code<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
|
fn code<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
|
||||||
|
fn boxed<'a>(s: Box<dyn Display + 'a>) -> Box<dyn Display + 'a> {
|
||||||
|
Box::new(format!(
|
||||||
|
" {} {}",
|
||||||
|
"Error"
|
||||||
|
.if_supports_color(Stdout, |s| s.red())
|
||||||
|
.if_supports_color(Stdout, |s| s.bold()),
|
||||||
|
format!("{s}").if_supports_color(Stdout, |s| s.red())
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
Error::DuplicateModule { .. } => Some(Box::new("aiken::module::duplicate")),
|
Error::DuplicateModule { .. } => Some(boxed(Box::new("aiken::module::duplicate"))),
|
||||||
Error::FileIo { .. } => None,
|
Error::FileIo { .. } => None,
|
||||||
Error::Blueprint(e) => e.code(),
|
Error::Blueprint(e) => e.code().map(boxed),
|
||||||
Error::ImportCycle { .. } => Some(Box::new("aiken::module::cyclical")),
|
Error::ImportCycle { .. } => Some(boxed(Box::new("aiken::module::cyclical"))),
|
||||||
Error::Parse { .. } => Some(Box::new("aiken::parser")),
|
Error::Parse { .. } => Some(boxed(Box::new("aiken::parser"))),
|
||||||
Error::Type { error, .. } => Some(Box::new(format!(
|
Error::Type { error, .. } => Some(boxed(Box::new(format!(
|
||||||
"aiken::check{}",
|
"aiken::check{}",
|
||||||
error.code().map(|s| format!("::{s}")).unwrap_or_default()
|
error.code().map(|s| format!("::{s}")).unwrap_or_default()
|
||||||
))),
|
)))),
|
||||||
Error::StandardIo(_) => None,
|
Error::StandardIo(_) => None,
|
||||||
Error::MissingManifest { .. } => None,
|
Error::MissingManifest { .. } => None,
|
||||||
Error::TomlLoading { .. } => Some(Box::new("aiken::loading::toml")),
|
Error::TomlLoading { .. } => Some(boxed(Box::new("aiken::loading::toml"))),
|
||||||
Error::Format { .. } => None,
|
Error::Format { .. } => None,
|
||||||
Error::TestFailure { path, .. } => Some(Box::new(path.to_str().unwrap_or(""))),
|
Error::TestFailure { path, .. } => Some(boxed(Box::new(path.to_str().unwrap_or("")))),
|
||||||
Error::Http(_) => Some(Box::new("aiken::packages::download")),
|
Error::Http(_) => Some(Box::new("aiken::packages::download")),
|
||||||
Error::ZipExtract(_) => None,
|
Error::ZipExtract(_) => None,
|
||||||
Error::JoinError(_) => None,
|
Error::JoinError(_) => None,
|
||||||
Error::UnknownPackageVersion { .. } => Some(Box::new("aiken::packages::resolve")),
|
Error::UnknownPackageVersion { .. } => {
|
||||||
Error::UnableToResolvePackage { .. } => Some(Box::new("aiken::package::download")),
|
Some(boxed(Box::new("aiken::packages::resolve")))
|
||||||
|
}
|
||||||
|
Error::UnableToResolvePackage { .. } => {
|
||||||
|
Some(boxed(Box::new("aiken::package::download")))
|
||||||
|
}
|
||||||
Error::Json { .. } => None,
|
Error::Json { .. } => None,
|
||||||
Error::MalformedStakeAddress { .. } => None,
|
Error::MalformedStakeAddress { .. } => None,
|
||||||
Error::NoValidatorNotFound { .. } => None,
|
Error::NoValidatorNotFound { .. } => None,
|
||||||
Error::MoreThanOneValidatorFound { .. } => None,
|
Error::MoreThanOneValidatorFound { .. } => None,
|
||||||
Error::Module(e) => e.code(),
|
Error::Module(e) => e.code().map(boxed),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -532,14 +546,24 @@ impl Diagnostic for Warning {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn code<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
|
fn code<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
|
||||||
|
fn boxed<'a>(s: Box<dyn Display + 'a>) -> Box<dyn Display + 'a> {
|
||||||
|
Box::new(format!(
|
||||||
|
" {} {}",
|
||||||
|
"Warning"
|
||||||
|
.if_supports_color(Stdout, |s| s.yellow())
|
||||||
|
.if_supports_color(Stdout, |s| s.bold()),
|
||||||
|
format!("{s}").if_supports_color(Stdout, |s| s.yellow())
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
Warning::Type { warning, .. } => Some(Box::new(format!(
|
Warning::Type { warning, .. } => Some(boxed(Box::new(format!(
|
||||||
"aiken::check{}",
|
"aiken::check{}",
|
||||||
warning.code().map(|s| format!("::{s}")).unwrap_or_default()
|
warning.code().map(|s| format!("::{s}")).unwrap_or_default()
|
||||||
))),
|
)))),
|
||||||
Warning::NoValidators => Some(Box::new("aiken::check")),
|
Warning::NoValidators => Some(boxed(Box::new("aiken::check"))),
|
||||||
Warning::DependencyAlreadyExists { .. } => {
|
Warning::DependencyAlreadyExists { .. } => {
|
||||||
Some(Box::new("aiken::packages::already_exists"))
|
Some(boxed(Box::new("aiken::packages::already_exists")))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,7 @@ impl Display for EvalHint {
|
||||||
)),
|
)),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
.ok_or(fmt::Error::default())?;
|
.ok_or(fmt::Error)?;
|
||||||
|
|
||||||
f.write_str(&msg)
|
f.write_str(&msg)
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ struct Summary {
|
||||||
impl Display for Summary {
|
impl Display for Summary {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
f.write_str(&format!(
|
f.write_str(&format!(
|
||||||
"{}\n {} {}, {} {}",
|
" {} {} {}, {} {}",
|
||||||
"Summary"
|
"Summary"
|
||||||
.if_supports_color(Stderr, |s| s.purple())
|
.if_supports_color(Stderr, |s| s.purple())
|
||||||
.if_supports_color(Stderr, |s| s.bold()),
|
.if_supports_color(Stderr, |s| s.bold()),
|
||||||
|
@ -41,14 +41,16 @@ impl Display for Summary {
|
||||||
} else {
|
} else {
|
||||||
"errors"
|
"errors"
|
||||||
}
|
}
|
||||||
.if_supports_color(Stderr, |s| s.red()),
|
.if_supports_color(Stderr, |s| s.red())
|
||||||
|
.if_supports_color(Stderr, |s| s.bold()),
|
||||||
self.warning_count,
|
self.warning_count,
|
||||||
if self.warning_count == 1 {
|
if self.warning_count == 1 {
|
||||||
"warning"
|
"warning"
|
||||||
} else {
|
} else {
|
||||||
"warnings"
|
"warnings"
|
||||||
}
|
}
|
||||||
.if_supports_color(Stderr, |s| s.yellow()),
|
.if_supports_color(Stderr, |s| s.yellow())
|
||||||
|
.if_supports_color(Stderr, |s| s.bold()),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,7 +109,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"\n{}",
|
"{}",
|
||||||
Summary {
|
Summary {
|
||||||
warning_count,
|
warning_count,
|
||||||
error_count: errs.len(),
|
error_count: errs.len(),
|
||||||
|
@ -117,7 +119,7 @@ where
|
||||||
return Err(ExitFailure::into_report());
|
return Err(ExitFailure::into_report());
|
||||||
} else {
|
} else {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"\n{}",
|
"{}",
|
||||||
Summary {
|
Summary {
|
||||||
error_count: 0,
|
error_count: 0,
|
||||||
warning_count
|
warning_count
|
||||||
|
|
Loading…
Reference in New Issue