Adapt narratable impl for DiagnosticChain

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
Matthias Beyer 2022-04-28 12:47:36 +02:00
parent 4cddd6e684
commit e37fcc6e31
1 changed files with 7 additions and 3 deletions

View File

@ -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)?;
}
}