Fix pretty node errors and add tests
MODIFY
packages/@romejs/core/test-worker/TestWorkerRunner.ts
packages/@romejs/core/test-worker/TestWorkerRunner.ts
@@ -85,8 +85,8 @@ function cleanFrames(frames: ErrorFrames): ErrorFrames {
if (latestTestWorkerFrame === undefined) {
latestTestWorkerFrame = frames.find((frame) => {
return (
- frame.typeName !== undefined &&
- frame.typeName.includes("$TestWorkerRunner")
+ frame.filename !== undefined &&
+ frame.filename.includes("TestWorkerRunner")
);
});
}

ADD
packages/@romejs/node/errors.test.ts
+import {test} from "rome";
+import {convertPossibleNodeError} from "./errors";
+import {initErrorHooks} from "@romejs/v8";
+
+// Always on in Rome processes
+initErrorHooks();
+
+test(
+ "ENOENT conversion",
+ (t) => {
+ const nodeErr: NodeJS.ErrnoException = new Error();
+ nodeErr.code = "ENOENT";
+ nodeErr.path = "/foo";
+
+ const betterErr = convertPossibleNodeError(nodeErr);
+ t.inlineSnapshot(betterErr.message, "'/foo' does not exist");
+ t.true(
+ betterErr.stack !== undefined &&
+ !betterErr.stack.includes("changeMessage"),
+ );
+ },
+);

MODIFY
packages/@romejs/node/errors.ts
packages/@romejs/node/errors.ts
import {ERROR_FRAMES_PROP, ErrorWithFrames} from "@romejs/v8";
-// rome-ignore lint/js/noShadowRestrictedNames
-type Error = NodeJS.ErrnoException;
-
function changeMessage(old: ErrorWithFrames, msg: string): Error {
const err: ErrorWithFrames = new Error(msg);
@@ -18,7 +15,10 @@ function changeMessage(old: ErrorWithFrames, msg: string): Error {
return err;
}
-function convertNodeErrorWithPath(err: Error, path: string): Error {
+function convertNodeErrorWithPath(
+ err: NodeJS.ErrnoException,
+ path: string,
+): Error {
switch (err.code) {
case "ENOENT":
return changeMessage(err, `'${path}' does not exist`);
@@ -31,7 +31,7 @@ function convertNodeErrorWithPath(err: Error, path: string): Error {
}
}
-export function convertPossibleNodeError(err: Error): Error {
+export function convertPossibleNodeError(err: NodeJS.ErrnoException): Error {
if (err.path !== undefined) {
return convertNodeErrorWithPath(err, err.path);
}

MODIFY
packages/@romejs/v8/errors.ts
packages/@romejs/v8/errors.ts
@@ -13,7 +13,7 @@ import {convertPossibleNodeError} from "@romejs/node";
export * from "./types";
-export const ERROR_FRAMES_PROP = Symbol();
+export const ERROR_FRAMES_PROP = "ERROR_FRAMES";
export type ErrorWithFrames = Error & {
[ERROR_FRAMES_PROP]?: unknown;

Fix pretty node errors and add tests (#632)