Skip to content

feat: 🎸 improve flags validation errors - #1290

Merged
streamich merged 3 commits into
masterfrom
fix/arg-validation
Sep 10, 2026
Merged

streamich merged 3 commits into
masterfrom
fix/arg-validation

Conversation

@streamich

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI lite review requested due to automatic review settings September 10, 2026 13:12

Copilot AI 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.

🟡 Changes recommended

It introduces observable Node-compatibility regressions in error shape/codes (notably argErrors tagging and encoding error codes) that should be corrected before approval.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR refactors argument/option validation in fs-node and fs-node-utils to produce more Node-like validation errors (codes/messages) for callbacks, modes, and flags, and updates tests accordingly.

Changes:

  • Introduce argErrors helpers to generate ERR_INVALID_ARG_TYPE / ERR_INVALID_ARG_VALUE / ERR_OUT_OF_RANGE style errors.
  • Update modeToNumber() and flagsToNumber() to perform stricter validation and emit structured Node-style error codes/messages.
  • Adjust Volume tests to assert updated error codes/messages for invalid flags/mode/callback scenarios.
File summaries
File Description
packages/fs-node/src/util.ts Switch validation helpers and tighten validation logic for callbacks/modes/flags.
packages/fs-node/src/tests/volume.test.ts Update expectations for revised validation errors and add clarifying TODOs.
packages/fs-node-utils/src/encoding.ts Change invalid-encoding validation to use new arg error helpers.
packages/fs-node-utils/src/argErrors.ts Add new utilities for constructing Node-like argument validation errors.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +3 to +18
const withCode = <E extends Error>(error: E, code: string): E => {
(error as any).code = code;
const tagged = error.name + ' [' + code + ']';
Object.defineProperty(error, 'name', { value: tagged, enumerable: false, writable: true, configurable: true });
void error.stack;
delete (error as any).name;
Object.defineProperty(error, 'toString', {
value: function (this: Error) {
return tagged + ': ' + this.message;
},
enumerable: false,
writable: true,
configurable: true,
});
return error;
};

export function assertEncoding(encoding: string | undefined) {
if (encoding && !Buffer.isEncoding(encoding)) throw new errors.TypeError('ERR_INVALID_OPT_VALUE_ENCODING', encoding);
if (encoding && !Buffer.isEncoding(encoding)) throw invalidArgValue('encoding', encoding, 'is invalid encoding');
@streamich
streamich merged commit 91354b9 into master Sep 10, 2026
12 checks passed
@streamich
streamich deleted the fix/arg-validation branch September 10, 2026 18:15
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