Skip to content

Commit

Permalink
ensure formatError for terminal cannot throw trying to read a file
Browse files Browse the repository at this point in the history
  • Loading branch information
dmail committed Aug 13, 2024
1 parent 956930f commit 4d6c513
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { assert } from "@jsenv/assert";

import { parseAnsi } from "@jsenv/terminal-recorder/src/svg/parse_ansi.js";

// reset bold
Expand Down
2 changes: 1 addition & 1 deletion packages/related/test/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jsenv/test",
"version": "3.4.2",
"version": "3.4.3",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
42 changes: 22 additions & 20 deletions packages/related/test/src/execution/format_error_for_terminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,28 @@ export const formatErrorForTerminal = (
error.site.url.startsWith("file:") &&
typeof error.site.line === "number"
) {
const content = readFileSync(new URL(error.site.url), "utf8");
text += generateContentFrame({
content,
line: error.site.line,
column: error.site.column,
linesAbove: 2,
linesBelow: 0,
lineMaxWidth: process.stdout.columns,
format: (string, type) => {
return {
line_number_aside: () => ANSI.color(string, ANSI.GREY),
char: () => string,
marker_overflow_left: () => ANSI.color(string, ANSI.GREY),
marker_overflow_right: () => ANSI.color(string, ANSI.GREY),
marker_line: () => ANSI.color(string, ANSI.RED),
marker_column: () => ANSI.color(string, ANSI.RED),
}[type]();
},
});
text += `\n`;
try {
const content = readFileSync(new URL(error.site.url), "utf8");
text += generateContentFrame({
content,
line: error.site.line,
column: error.site.column,
linesAbove: 2,
linesBelow: 0,
lineMaxWidth: process.stdout.columns,
format: (string, type) => {
return {
line_number_aside: () => ANSI.color(string, ANSI.GREY),
char: () => string,
marker_overflow_left: () => ANSI.color(string, ANSI.GREY),
marker_overflow_right: () => ANSI.color(string, ANSI.GREY),
marker_line: () => ANSI.color(string, ANSI.RED),
marker_column: () => ANSI.color(string, ANSI.RED),
}[type]();
},
});
text += `\n`;
} catch {}
}
}
text += `${error.name}: ${error.message}`;
Expand Down

0 comments on commit 4d6c513

Please sign in to comment.