Skip to content

Commit

Permalink
Remove context error message from DiagnosedError.
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-dfinity committed Dec 3, 2024
1 parent 27d5c71 commit e9a127a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/dfx/src/lib/diagnosis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ pub type Diagnosis = (Option<String>, Option<String>);
pub const NULL_DIAGNOSIS: Diagnosis = (None, None);

#[derive(ThisError, Debug)]
// This message will appear in the context trace of the stack. The diagnosis should not be displayed there yet.
#[error("Diagnosis was added here.")]
/// If you do not need the generic error diagnosis to run, you can add a DiagnosedError with .context(err: DiagnosedError).
/// In that case, no extra diagnosis is attempted and the last-added explanation and suggestion are printed out.
pub struct DiagnosedError {
/// A user-friendly explanation of what went wrong.
pub error_explanation: Option<String>,
Expand All @@ -29,6 +25,12 @@ pub struct DiagnosedError {
pub action_suggestion: Option<String>,
}

impl std::fmt::Display for DiagnosedError {
fn fmt(&self, _f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Ok(())
}
}

impl DiagnosedError {
pub fn new(error_explanation: String, action_suggestion: String) -> Self {
Self {
Expand Down
4 changes: 4 additions & 0 deletions src/dfx/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ fn print_error_and_diagnosis(err: Error, error_diagnosis: Diagnosis) {

// print error chain stack
for (level, cause) in err.chain().enumerate() {
if cause.to_string().is_empty() {
continue;
}

let (color, prefix) = if level == 0 {
(term::color::RED, "Error")
} else {
Expand Down

0 comments on commit e9a127a

Please sign in to comment.