Repository navigation
Give node:fs errors errno, full path and dest like Node - #8588
Conversation
There was a problem hiding this comment.
Superseded by the review of
db512c52.
This review, of 49cb4e46
💬 Approved with comments — The change is correct and well tested. The only notes are a non-blocking suggestion about eager string building in link() and a small wording fix in a comment.
Findings: 1 info · 1 suggestion (2 are inline comments on the diff)
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
📋 Code Quality: 💬 1 suggestion
The change is correct. One small point: link() builds its error strings on every call instead of only when it throws.
Recommendation: 💬 Optional Nits
- [SUGGESTION] link() builds errPath/errDest strings on every call instead of only when an error is thrown (
src/workerd/api/filesystem.c++:387)
View full review
src/workerd/api/filesystem.c++:387-391:link()buildserrPathanderrDestwithkj::str(...)on every call, and buildserrPatha second time whenrawTargetis set. The other functions this pull request changes (unlink,readAll,writeAll,renameOrCopy,mkdir,rm) use lazy lambdas, which matches the description's statement that the path strings are built only when an error is thrown.
Everything else checks out:
errnois the negative UV value.- Explicit-message paths keep their text and still carry
pathanddest. - The
copyFileCOPYFILE_EXCL path now reports source and destination the way Node does.
📝 Documentation: 💬 1 info
One comment describes the dest suffix condition a little imprecisely.
Recommendation: 💬 Optional Nits
- [INFO] Comment says dest is appended whenever there is a dest; the code requires path as well (
src/rust/node-exceptions/lib.rs:254)
View full review
src/rust/node-exceptions/lib.rs:254: the comment says-> 'dest'is appended "when there is a dest", but the formatter appends it only whenpathis also present.
✅ All other checks passed
🔒 Security: ✅ LGTM
No security issues found.
📖 AGENTS.md: ✅ LGTM
This pull request does not change any AGENTS.md files.
⚡ Performance: ✅ LGTM
No performance issues found.
Reviewed commit: 49cb4e46
49cb4e4 to
db512c5
Compare
There was a problem hiding this comment.
Superseded by the review of
abdad18a.
This review, of db512c52
✅ Approved — Both earlier notes (eager string building in link() and the lib.rs comment wording) are fixed, and no new issues were found in this commit.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
The change only fills in errno, path and dest on errors. Those values come from the caller's own normalized paths and go back only to that same caller. It adds no new input surface.
📖 AGENTS.md: ✅ LGTM
This pull request does not change any AGENTS.md files.
📋 Code Quality: ✅ LGTM
errPath and errDest in link() (src/workerd/api/filesystem.c++:387-393) are now lambdas, so the strings are built only when an error is thrown. The symbolic-link branch reads the target for its error from symlink->getRawTarget(), not from the moved-from rawTarget. ERR_EEXIST and both copyFile COPYFILE_EXCL call sites report source as path and destination as dest. The new test covers the sync, callback and promises APIs.
⚡ Performance: ✅ LGTM
Path and dest strings are built only when an error is thrown. The one addition on the success path is a cheap addRef() in the symbolic-link branch.
📝 Documentation: ✅ LGTM
The comment at src/rust/node-exceptions/lib.rs:254 now says the dest suffix is appended when both path and dest are present. That matches the formatter.
Reviewed commit: db512c52
db512c5 to
abdad18
Compare
There was a problem hiding this comment.
Superseded by the review of
d2bab8a1.
This review, of abdad18a
✅ Approved — The only change since the last review adds Rust unit tests for the errno and dest formatting. No issues were found.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
The added unit tests do not expose anything new. Error path and dest values still come from the caller's own normalized paths.
📖 AGENTS.md: ✅ LGTM
This pull request does not change any AGENTS.md files.
📋 Code Quality: ✅ LGTM
The only change since the last review is the new assertions in src/rust/node-exceptions/lib-test.rs. They cover the -> 'dest' message suffix and the negative errno. The C++ and TypeScript changes reviewed earlier have not changed.
⚡ Performance: ✅ LGTM
The added unit-test assertions have no runtime performance impact.
📝 Documentation: ✅ LGTM
No documentation issues.
Reviewed commit: abdad18a
guybedford
left a comment
There was a problem hiding this comment.
Nice work. I compared this against Node 22 over a wider set of cases and code, errno, path and dest match for every function touched here. A few comments inline, none blocking.
One thing on the commit message: the compat note says only properties are added or filled in, but some existing values do change (path from the last component to the full path, the COPYFILE_EXCL EEXIST path from the destination to the source, and the message text). I agree no flag is needed, but the message should record that as the decision.
node:fs errors from workerd never had `errno`, since the error object built in Rust set only `code`, `syscall`, `path` and `dest`. Several calls reported only the last path component as `path` (`unlinkSync('/tmp/a/missing')` gave `'missing'`, and so did `rmdir`, `mkdir` and `mkdtemp`), and others left it out (`writeFile` with `wx`, `readFile` and `writeFile` on a directory, `mkdir` under a file). Two-path calls (`rename`, `copyFile`, `link`, `symlink`) never set `dest`. Refs #4313.
In this patch every UV error sets a negative `errno`, and its default message ends with ` -> 'dest'` when there is a dest, as in Node. readAll, writeAll, unlink, rm, mkdir, link and renameOrCopy pass the full normalized path, and the two-path calls pass `path` (source or link target) and `dest` (new name) the way Node does. The `COPYFILE_EXCL` EEXIST now reports the source as `path` and the destination as `dest`. The unlink and link errors that restated the default text (`File not found`, `File already exists`, ...) now use the default message, so it names the path like Node's. The path strings are built only when an error is thrown.
Compat: besides adding `errno` and `dest`, this changes existing values: `path` goes from the last component to the full path, the `COPYFILE_EXCL` EEXIST `path` goes from the destination to the source, and messages change. Each one moves to what Node reports, and code that branches on these errors checks `code`, which is unchanged, so we accept the change without a compat flag.
The new fs-errors-test checks code, errno, syscall, path and dest for ENOENT, EEXIST, ENOTDIR, EISDIR and ENOTEMPTY across the sync, callback and promises APIs, plus the unlink, rename and link messages, and fails without the fix.
abdad18 to
d2bab8a
Compare
There was a problem hiding this comment.
Superseded by the review of
14a22ef4.
This review, of d2bab8a1
✅ Approved — No issues found. The earlier comments are addressed: call sites that only repeated the default message now use it, the comment about the code prefix is corrected, and the commit message records the compatibility decision.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
The error path and dest values come from the caller's own normalized paths in the virtual filesystem. No new information is exposed.
📖 AGENTS.md: ✅ LGTM
This pull request does not change any AGENTS.md files.
📋 Code Quality: ✅ LGTM
The THROW_ERR_UV_* call sites pass the full normalized path and dest. The errPath and errDest lambdas build their strings only when an error is thrown. In the symlink branch of link, the error path uses symlink->getRawTarget() and never reads the moved-from rawTarget. The Rust tests in lib-test.rs cover the negative errno and the -> 'dest' suffix in the message.
⚡ Performance: ✅ LGTM
Path strings are built only when an error is thrown, so calls that succeed allocate nothing extra.
📝 Documentation: ✅ LGTM
No documentation issues.
Reviewed commit: d2bab8a1
There was a problem hiding this comment.
✅ Approved — No issues found. The earlier comments are addressed: call sites that only repeated the default message now use it, the comment about the code prefix is corrected, and the commit message records the compatibility decision.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
The error path and dest values come from the caller's own normalized paths in the virtual filesystem. No new information is exposed.
📖 AGENTS.md: ✅ LGTM
This pull request does not change any AGENTS.md files.
📋 Code Quality: ✅ LGTM
The THROW_ERR_UV_* call sites pass the full normalized path and dest. The errPath and errDest lambdas build their strings only when an error is thrown. In the symlink branch of link, the error path uses symlink->getRawTarget() and never reads the moved-from rawTarget. The Rust tests in lib-test.rs cover the negative errno and the -> 'dest' suffix in the message.
⚡ Performance: ✅ LGTM
Path strings are built only when an error is thrown, so calls that succeed allocate nothing extra.
📝 Documentation: ✅ LGTM
No documentation issues.
Reviewed commit: 14a22ef4 — same changes as d2bab8a1, so this is that commit's review (no new review was run; line numbers are as of d2bab8a1)
node:fs errors from workerd never had
errno, since the error object built in Rust set onlycode,syscall,pathanddest. Several calls reported only the last path component aspath(unlinkSync('/tmp/a/missing')gave'missing', and so didrmdir,mkdirandmkdtemp), and others left it out (writeFilewithwx,readFileandwriteFileon a directory,mkdirunder a file). Two-path calls (rename,copyFile,link,symlink) never setdest. Refs #4313.In this patch every UV error sets a negative
errno, and its default message ends with-> 'dest'when there is a dest, as in Node. readAll, writeAll, unlink, rm, mkdir, link and renameOrCopy pass the full normalized path, and the two-path calls passpath(source or link target) anddest(new name) the way Node does. TheCOPYFILE_EXCLEEXIST now reports the source aspathand the destination asdest. The unlink and link errors that restated the default text (File not found,File already exists, ...) now use the default message, so it names the path like Node's. The path strings are built only when an error is thrown.Compat: besides adding
errnoanddest, this changes existing values:pathgoes from the last component to the full path, theCOPYFILE_EXCLEEXISTpathgoes from the destination to the source, and messages change. Each one moves to what Node reports, and code that branches on these errors checkscode, which is unchanged, so we accept the change without a compat flag.The new fs-errors-test checks code, errno, syscall, path and dest for ENOENT, EEXIST, ENOTDIR, EISDIR and ENOTEMPTY across the sync, callback and promises APIs, plus the unlink, rename and link messages, and fails without the fix.