From e37fcc6e31c4042b916382fc590a0c3ffc3153ee Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 28 Apr 2022 12:47:36 +0200 Subject: [PATCH] Adapt narratable impl for DiagnosticChain Signed-off-by: Matthias Beyer --- src/handlers/narratable.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/handlers/narratable.rs b/src/handlers/narratable.rs index c9b656a..5ff3ae9 100644 --- a/src/handlers/narratable.rs +++ b/src/handlers/narratable.rs @@ -2,7 +2,7 @@ use std::fmt; use unicode_width::{UnicodeWidthChar, UnicodeWidthStr}; -use crate::chain::Chain; +use crate::diagnostic_chain::DiagnosticChain; use crate::protocol::{Diagnostic, Severity}; use crate::{LabeledSpan, MietteError, ReportHandler, SourceCode, SourceSpan, SpanContents}; @@ -80,8 +80,12 @@ impl NarratableReportHandler { } fn render_causes(&self, f: &mut impl fmt::Write, diagnostic: &(dyn Diagnostic)) -> fmt::Result { - if let Some(cause) = diagnostic.source() { - for error in Chain::new(cause) { + if let Some(cause_iter) = diagnostic + .diagnostic_source() + .map(DiagnosticChain::from_diagnostic) + .or_else(|| diagnostic.source().map(DiagnosticChain::from_stderror)) + { + for error in cause_iter { writeln!(f, " Caused by: {}", error)?; } }