Skip to content

Give node:fs errors errno, full path and dest like Node - #8588

Merged
littledivy merged 2 commits into
mainfrom
littledivy/2026-11-18-fs-enoent-path
Nov 21, 2026
Merged

littledivy merged 2 commits into
mainfrom
littledivy/2026-11-18-fs-enoent-path

Conversation

@littledivy

@littledivy littledivy commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

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.

@littledivy
littledivy requested review from a team as code owners November 18, 2026 05:31

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() builds errPath and errDest with kj::str(...) on every call, and builds errPath a second time when rawTarget is 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:

  • errno is the negative UV value.
  • Explicit-message paths keep their text and still carry path and dest.
  • The copyFile COPYFILE_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 when path is 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

Comment thread src/rust/node-exceptions/lib.rs Resolved
Comment thread src/workerd/api/filesystem.c++ Resolved
@littledivy
littledivy force-pushed the littledivy/2026-11-18-fs-enoent-path branch from 49cb4e4 to db512c5 Compare November 18, 2026 05:38

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@littledivy
littledivy force-pushed the littledivy/2026-11-18-fs-enoent-path branch from db512c5 to abdad18 Compare November 18, 2026 05:54

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 guybedford left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/workerd/api/filesystem.c++ Resolved
Comment thread src/rust/node-exceptions/lib.rs Resolved
Comment thread src/rust/node-exceptions/lib.rs Resolved
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.
@littledivy
littledivy force-pushed the littledivy/2026-11-18-fs-enoent-path branch from abdad18 to d2bab8a Compare November 19, 2026 06:16

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@clanky-the-clanker clanky-the-clanker Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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)

@littledivy
littledivy merged commit 335ad62 into main Nov 21, 2026
26 of 37 checks passed
@littledivy
littledivy deleted the littledivy/2026-11-18-fs-enoent-path branch November 21, 2026 03:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants