mirror of
https://github.com/denoland/deno.git
synced 2024-12-24 16:19:12 -05:00
fix(node/fs): missing uv error context for readFile (#27011)
Dart's Node wrapper code in `npm:sass` does string slicing on the thrown error message which broke because of our missing uv error context. Code in question: ```js _systemErrorToFileSystemException0(callback) { var error, t1, exception, t2; try { t1 = callback.call$0(); return t1; } catch (exception) { error = A.unwrapException(exception); if (!type$.JsSystemError._is(error)) throw exception; t1 = error; t2 = J.getInterceptor$x(t1); throw A.wrapException(new A.FileSystemException0(J.substring$2$s(t2.get$message(t1), (A.S(t2.get$code(t1)) + ": ").length, J.get$length$asx(t2.get$message(t1)) - (", " + A.S(t2.get$syscall(t1)) + " '" + A.S(t2.get$path(t1)) + "'").length), J.get$path$x(error))); } } ``` Fixes https://github.com/denoland/deno/issues/26994
This commit is contained in:
parent
4ded7519e9
commit
50538ba35d
2 changed files with 26 additions and 3 deletions
|
@ -88,7 +88,7 @@ export function readFile(
|
|||
}
|
||||
const buffer = maybeDecode(data, encoding);
|
||||
(cb as BinaryCallback)(null, buffer);
|
||||
}, (err) => cb && cb(denoErrorToNodeError(err)));
|
||||
}, (err) => cb && cb(denoErrorToNodeError(err, { path, syscall: "open" })));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,7 @@ export function readFileSync(
|
|||
try {
|
||||
data = Deno.readFileSync(path);
|
||||
} catch (err) {
|
||||
throw denoErrorToNodeError(err);
|
||||
throw denoErrorToNodeError(err, { path, syscall: "open" });
|
||||
}
|
||||
const encoding = getEncoding(opt);
|
||||
if (encoding && encoding !== "binary") {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
import { assertCallbackErrorUncaught } from "../_test_utils.ts";
|
||||
import { promises, readFile, readFileSync } from "node:fs";
|
||||
import * as path from "@std/path";
|
||||
import { assert, assertEquals } from "@std/assert";
|
||||
import { assert, assertEquals, assertMatch } from "@std/assert";
|
||||
|
||||
const moduleDir = path.dirname(path.fromFileUrl(import.meta.url));
|
||||
const testData = path.resolve(moduleDir, "testdata", "hello.txt");
|
||||
|
@ -121,3 +121,26 @@ Deno.test("fs.promises.readFile with no arg call rejects with error correctly",
|
|||
// @ts-ignore no arg call needs to be supported
|
||||
await promises.readFile().catch((_e) => {});
|
||||
});
|
||||
|
||||
Deno.test("fs.readFile error message contains path + syscall", async () => {
|
||||
const path = "/does/not/exist";
|
||||
const err = await new Promise((resolve) => {
|
||||
readFile(path, "utf-8", (err) => resolve(err));
|
||||
});
|
||||
if (err instanceof Error) {
|
||||
assert(err.message.includes(path), "Path not found in error message");
|
||||
assertMatch(err.message, /[,\s]open\s/);
|
||||
}
|
||||
});
|
||||
|
||||
Deno.test("fs.readFileSync error message contains path + syscall", () => {
|
||||
const path = "/does/not/exist";
|
||||
try {
|
||||
readFileSync(path, "utf-8");
|
||||
} catch (err) {
|
||||
if (err instanceof Error) {
|
||||
assert(err.message.includes(path), "Path not found in error message");
|
||||
assertMatch(err.message, /[,\s]open\s/);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue