Skip to content

benchmark: throw on invalid type in fs and webstorage - #66647

Closed
irontaek wants to merge 2 commits into
nodejs:mainfrom
irontaek:benchmark-throw-invalid-type
Closed

irontaek wants to merge 2 commits into
nodejs:mainfrom
irontaek:benchmark-throw-invalid-type

Conversation

@irontaek

Copy link
Copy Markdown
Contributor

In 21 fs and webstorage benchmarks, the default: branch of the type switch
creates new Error('Invalid type') without throwing it. An unknown type then
falls through and benchmarks an undefined path instead of failing.

Before:

$ node benchmark/fs/bench-existsSync.js type=bogus n=10
fs/bench-existsSync.js n=10 type="bogus": 42,410.43975384981

After, the same command throws Error: Invalid type. Every type listed in each
benchmark's config still has a matching case, so valid runs are unchanged.

Disclosure: this change was found by a static check for discarded new Error(...)
expressions and prepared with a coding agent, which also ran the commands above.
I'll handle review feedback myself.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/performance

@nodejs-github-bot nodejs-github-bot added benchmark Issues and PRs related to Node.js benchmarks and benchmarking infrastructure. fs Issues and PRs related to file-system APIs and the fs module. labels Oct 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Welcome to Node.js, and thank you for your first contribution!

Before review, please take a moment to read:

Please make sure every commit is signed off. For a first pull request, GitHub Actions require collaborator approval and Jenkins CI must be started by a collaborator or triager, so an initial wait is normal.

Caution

AgentScan found account activity patterns that may be consistent with automation. This is a heuristic, not proof that this pull request was opened by an agent or violates policy. AI-assisted contributions are permitted, but automated tooling must not open pull requests without advance approval, and contributors must personally understand, test, verify, and take responsibility for every submitted change. See the AgentScan analysis, AI use policy, and automation policy for additional context.

@atlowChemi

Copy link
Copy Markdown
Member

Probably worth adding a lint rule that doesn't allow calling the error constructor without throwing/assigning/returning it.
Maybe no-new could work, though might cause unrelated noise

@irontaek

Copy link
Copy Markdown
Contributor Author

Good idea. no-new would flag ~310 sites (mostly tests that construct objects for side effects). A narrower selector next to the existing ThrowStatement one, ExpressionStatement > NewExpression[callee.name=/Error$/], flags only 2 sites after this PR — both intentional (benchmark/error/error.js measures Error construction, and test/parallel/test-errors-systemerror.js asserts the constructor throws), which I disabled inline. Added it as a second commit.

@MikeMcC399

This comment was marked as resolved.

@irontaek
irontaek force-pushed the benchmark-throw-invalid-type branch from 622bc2e to 2c08205 Compare October 13, 2026 15:08
@irontaek

Copy link
Copy Markdown
Contributor Author

Thanks, added the sign-off to both commits.

@codecov

codecov Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.73%. Comparing base (5884b8e) to head (b66ce2a).
⚠️ Report is 22 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66647      +/-   ##
==========================================
+ Coverage   90.71%   90.73%   +0.01%     
==========================================
  Files         801      801              
  Lines      280906   280906              
  Branches    54249    54258       +9     
==========================================
+ Hits       254832   254877      +45     
+ Misses      16246    16193      -53     
- Partials     9828     9836       +8     

see 35 files with indirect coverage changes

🚀 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.

@irontaek

Copy link
Copy Markdown
Contributor Author

Friendly ping for review. Both commits now include sign-offs, and all GitHub checks are passing. This also includes the targeted lint rule suggested above. Is there anything else needed from my side?

@irontaek

Copy link
Copy Markdown
Contributor Author

@atlowChemi since the lint rule here came from your suggestion, would you be able to take a look when you have a moment? Happy to adjust the selector or split the rule into a separate PR if that's easier to review.

@mcollina mcollina 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.

lgtm

@atlowChemi

Copy link
Copy Markdown
Member

@irontaek can you rebase over main so we don't land the PR and have the lint rule error on code in main not fixed by the PR?

The default branch of the type switch constructed an Error without
throwing it, so an unknown type silently benchmarked an undefined
path instead of failing.

Assisted-by: a closed-source coding agent
Signed-off-by: Minho Yoo <13810291+irontaek@users.noreply.github.com>
Add a no-restricted-syntax selector next to the existing
ThrowStatement one. It would have caught the benchmark bug fixed in
the previous commit; the two intentional sites are disabled inline.

Assisted-by: a closed-source coding agent
Signed-off-by: Minho Yoo <13810291+irontaek@users.noreply.github.com>
@irontaek
irontaek force-pushed the benchmark-throw-invalid-type branch from 2c08205 to b66ce2a Compare November 20, 2026 12:45
@irontaek

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (2d8a7f3). I also ran ESLint with only the new selector enabled across lib/, test/ and benchmark/ on the rebased tree. It reports no hits beyond the ones this PR already handles, and lint-js-and-md passes on the new head.

@mcollina mcollina 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.

Lgtm

@mcollina mcollina added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 21, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 21, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@atlowChemi atlowChemi added commit-queue PRs queued for automated landing through the Commit Queue. commit-queue-rebase PRs the Commit Queue should land as multiple self-contained commits. labels Nov 22, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in 2b365b2...2ab7bc0

nodejs-github-bot pushed a commit that referenced this pull request Nov 22, 2026
The default branch of the type switch constructed an Error without
throwing it, so an unknown type silently benchmarked an undefined
path instead of failing.

Assisted-by: a closed-source coding agent
Signed-off-by: Minho Yoo <13810291+irontaek@users.noreply.github.com>
PR-URL: #66647
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
nodejs-github-bot pushed a commit that referenced this pull request Nov 22, 2026
Add a no-restricted-syntax selector next to the existing
ThrowStatement one. It would have caught the benchmark bug fixed in
the previous commit; the two intentional sites are disabled inline.

Assisted-by: a closed-source coding agent
Signed-off-by: Minho Yoo <13810291+irontaek@users.noreply.github.com>
PR-URL: #66647
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
@nodejs-github-bot nodejs-github-bot removed the commit-queue PRs queued for automated landing through the Commit Queue. label Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agentscan:automated-account benchmark Issues and PRs related to Node.js benchmarks and benchmarking infrastructure. commit-queue-rebase PRs the Commit Queue should land as multiple self-contained commits. fs Issues and PRs related to file-system APIs and the fs module.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants