tamer: diagnose::report: Restore source line preview for invalid UTF-8

This was removed in a previous commit while working on simplifying the
implementation, with the hope of returning to it once things were in a
better place.  They are, so let's bring it back.

DEV-12151
main
Mike Gerwitz 2022-04-29 12:41:56 -04:00
parent f8dda12fae
commit 2ae6df38e7
2 changed files with 9 additions and 0 deletions

View File

@ -386,6 +386,11 @@ where
}),
]);
} else {
body.extend(vec![
SectionLine::SourceLinePadding,
SectionLine::SourceLine(srcline.into()),
SectionLine::SourceLinePadding,
]);
body.extend(
label.map(|l| SectionLine::Footnote(level, l)),
);

View File

@ -453,6 +453,7 @@ fn fallback_when_column_fails_to_resolve() {
let ctx = Context::from("invalid/utf8");
let span = ctx.span(4, 2);
let lossy = String::from_utf8_lossy(FILE_INVALID_UTF8);
assert_report!(
"column resolution failure",
@ -460,6 +461,9 @@ fn fallback_when_column_fails_to_resolve() {
format!("\
error: column resolution failure
--> invalid/utf8:1 bytes 4--6
|
1 | {lossy}
|
= error: an error we do not want to suppress
= help: unable to calculate columns because the line is not a valid UTF-8 string
= help: you have been provided with 0-indexed line-relative inclusive byte offsets