Skip to content

Implement util._errnoException and util._exceptionWithHostPort - #8848

Closed
littledivy wants to merge 1 commit into
mainfrom
littledivy/2026-11-24-node-util-errno-exc
Closed

littledivy wants to merge 1 commit into
mainfrom
littledivy/2026-11-24-node-util-errno-exc

Conversation

@littledivy

Copy link
Copy Markdown
Member

util._errnoException() and util._exceptionWithHostPort() threw ERR_METHOD_NOT_IMPLEMENTED. Node exposes both, and libraries that build Node-style errors for failed syscalls call them.

In this patch both build the same errors as Node 26's ErrnoException and ExceptionWithHostPort: a plain Error whose message is the syscall, the libuv error name and the details, with own errno, code and syscall properties (and address, plus port when it is non-zero), in Node's order. The name comes from the libuv table that getSystemErrorName() already uses, so the numbers are Linux's, as Node reports them on Linux. err is validated the same way, so a non-number throws ERR_INVALID_ARG_TYPE and anything but a negative integer throws ERR_OUT_OF_RANGE. The stack starts at the caller. Node's permission-model branch is left out, since workerd has no permission model.

No compat flag: both functions threw for every input, so the only change is that calls which threw ERR_METHOD_NOT_IMPLEMENTED now return an Error, or throw ERR_INVALID_ARG_TYPE / ERR_OUT_OF_RANGE for an invalid err. The new tests fail without the change.

@littledivy
littledivy requested review from a team as code owners November 24, 2026 03:55

@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 2de8a258.

This review, of 2384bcdf

✅ Approved — No issues found. Both functions match Node's behavior, reuse the existing validation and errno-name helpers, and come with tests.

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

No issues found. err is validated before use. syscall, address and additional only end up in the error message and properties. The change adds no new entry points or privileges.


📖 AGENTS.md: ✅ LGTM

No issues found.


📋 Code Quality: ✅ LGTM

No issues found. The shared errnoError helper builds the message and the errno/code/syscall properties in the same order Node does, and each exported function adds its own fields and stack capture.


⚡ Performance: ✅ LGTM

No issues found.


📝 Documentation: ✅ LGTM

No issues found.


Reviewed commit: 2384bcdf

`util._errnoException()` and `util._exceptionWithHostPort()` threw ERR_METHOD_NOT_IMPLEMENTED. Node exposes both, and libraries that build Node-style errors for failed syscalls call them.

In this patch both build the same errors as Node 26's ErrnoException and ExceptionWithHostPort: a plain Error whose message is the syscall, the libuv error name and the details, with own `errno`, `code` and `syscall` properties (and `address`, plus `port` when it is non-zero), in Node's order. The name comes from the libuv table that `getSystemErrorName()` already uses, so the numbers are Linux's, as Node reports them on Linux. `err` is validated the same way, so a non-number throws ERR_INVALID_ARG_TYPE and anything but a negative integer throws ERR_OUT_OF_RANGE. The stack starts at the caller. Node's permission-model branch is left out, since workerd has no permission model.

No compat flag: both functions threw for every input, so the only change is that calls which threw ERR_METHOD_NOT_IMPLEMENTED now return an Error, or throw ERR_INVALID_ARG_TYPE / ERR_OUT_OF_RANGE for an invalid `err`. The new tests fail without the change.
@littledivy
littledivy force-pushed the littledivy/2026-11-24-node-util-errno-exc branch from 2384bcd to 2de8a25 Compare November 24, 2026 04:02

@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. Both functions produce the same errors as Node, reuse the existing err validation and errno-name lookup, and the updated tests cover the edge cases.

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

err is validated before it is used. syscall, address and additional end up only in the error's message and properties. The change adds no entry points and grants no new privileges.


📖 AGENTS.md: ✅ LGTM

No issues found.


📋 Code Quality: ✅ LGTM

The shared errnoError helper sets the message and the errno, code and syscall properties in Node's order. validateSystemError narrows err to a number. The address and port handling, the original and additional formatting, and the Error.captureStackTrace calls all match Node. The updated tests cover property order, errno numbering, a negative port, an omitted port and invalid err values.


⚡ Performance: ✅ LGTM

Each function runs one validation, one error-name lookup and one stack capture per call. Neither is on a hot path.


📝 Documentation: ✅ LGTM

No issues found.


Reviewed commit: 2de8a258

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.71%. Comparing base (28068ef) to head (2de8a25).
⚠️ Report is 16 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8848      +/-   ##
==========================================
- Coverage   67.73%   67.71%   -0.03%     
==========================================
  Files         848      848              
  Lines      215725   215801      +76     
  Branches    32511    32511              
==========================================
  Hits       146121   146121              
- Misses      50404    50480      +76     
  Partials    19200    19200              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

2 participants