Improve failure chain on revert (#467)

This commit is contained in:
Ana Hobden 2023-05-17 09:01:36 -07:00 committed by GitHub
parent e3a5ffc8f7
commit 1c18698ee6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View file

@ -328,6 +328,12 @@ impl ActionError {
pub fn action_tag(&self) -> &ActionTag {
&self.action_tag
}
#[cfg(feature = "diagnostics")]
pub fn diagnostic(&self) -> String {
use crate::diagnostics::ErrorDiagnostic;
self.kind.diagnostic()
}
}
impl std::fmt::Display for ActionError {
@ -572,6 +578,10 @@ impl crate::diagnostics::ErrorDiagnostic for ActionErrorKind {
fn diagnostic(&self) -> String {
let static_str: &'static str = (self).into();
let context = match self {
Self::Child(child) => vec![child.diagnostic()],
Self::MultipleChildren(children) => {
children.iter().map(|child| child.diagnostic()).collect()
},
Self::Read(path, _)
| Self::Open(path, _)
| Self::Write(path, _)

View file

@ -97,7 +97,11 @@ impl crate::diagnostics::ErrorDiagnostic for NixInstallerError {
fn diagnostic(&self) -> String {
let static_str: &'static str = (self).into();
let context = match self {
Self::Action(action_error) => vec![action_error.action_tag().to_string()],
Self::Action(action_error) => vec![action_error.diagnostic().to_string()],
Self::ActionRevert(action_errors) => action_errors
.iter()
.map(|action_error| action_error.diagnostic().to_string())
.collect(),
_ => vec![],
};
return format!(