Open familyboat opened 4 weeks ago
I think there is some error wrapping going on here that needs to just be removed from the node:fs
code path.
Do you think adding the missing file path information is sufficient for this case. If so, i can make a PR. @lucacasonato
It is my first time to contribute to deno. So i follow the instruction in here. After everything set up, run cargo build -vv
. It exited in the fetching rust_v8 precompile stage(by the way, i am in China). So i can not make a PR.
If i am right, just addding path
parameter in this line:
https://github.com/denoland/deno/blob/f5caf9dd1b0f612e2a03e802d4dca41cb13a006b/ext/node/polyfills/_fs/_fs_stat.ts#L420 can fix this issue.
By using local version of rusty_v8 precompile, deno was built successfully.
I added the path
parameter in here:
https://github.com/denoland/deno/blob/f5caf9dd1b0f612e2a03e802d4dca41cb13a006b/ext/node/polyfills/_fs/_fs_stat.ts#L420
Change it to:
throw denoErrorToNodeError(err, { syscall: "stat", path: path.toString() });
Below is the test code:
import fs from "node:fs";
function readFileWithNode(file: string | URL) {
const type = typeof file === "string" ? "string" : "url";
try {
fs.statSync(file);
} catch (error: unknown) {
console.log(
`Error occurred while reading ${type} file with node: ${error}`,
);
}
}
function readFileWithDeno(file: string | URL) {
const type = typeof file === "string" ? "string" : "url";
try {
Deno.statSync(file);
} catch (error: unknown) {
console.log(
`Error occurred while reading ${type} file with deno: ${error}`,
);
}
}
const file = "non-exist-file";
const fileUrl = new URL(file, import.meta.url);
readFileWithNode(file);
readFileWithDeno(file);
readFileWithNode(fileUrl);
readFileWithDeno(fileUrl);
Output is:
Error occurred while reading string file with node: Error: ENOENT: no such file or directory, stat 'non-exist-file'
Error occurred while reading string file with deno: NotFound: No such file or directory (os error 2): stat 'non-exist-file'
Error occurred while reading url file with node: Error: ENOENT: no such file or directory, stat 'file:///root/test/node-file-error-message/non-exist-file'
Error occurred while reading url file with deno: NotFound: No such file or directory (os error 2): stat '/root/test/node-file-error-message/non-exist-file'
Do you think it is ok?
Version: Deno 1.46.1
Run below command:
The output is:
In this case, better error message(has path information) is useful for debug.