From e9a127af576a18854adda123e82097302f83dc79 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Tue, 3 Dec 2024 19:41:01 +0800 Subject: [PATCH] Remove context error message from DiagnosedError. --- src/dfx/src/lib/diagnosis.rs | 10 ++++++---- src/dfx/src/main.rs | 4 ++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/dfx/src/lib/diagnosis.rs b/src/dfx/src/lib/diagnosis.rs index b346341cf7..d90a133f11 100644 --- a/src/dfx/src/lib/diagnosis.rs +++ b/src/dfx/src/lib/diagnosis.rs @@ -17,10 +17,6 @@ pub type Diagnosis = (Option, Option); 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, @@ -29,6 +25,12 @@ pub struct DiagnosedError { pub action_suggestion: Option, } +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 { diff --git a/src/dfx/src/main.rs b/src/dfx/src/main.rs index 79a19d3542..85603b4657 100644 --- a/src/dfx/src/main.rs +++ b/src/dfx/src/main.rs @@ -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 {