Repository navigation
feat: 🎸 improve flags validation errors - #1290
Merged
Merged
Conversation
There was a problem hiding this comment.
🟡 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
argErrorshelpers to generateERR_INVALID_ARG_TYPE/ERR_INVALID_ARG_VALUE/ERR_OUT_OF_RANGEstyle errors. - Update
modeToNumber()andflagsToNumber()to perform stricter validation and emit structured Node-style error codes/messages. - Adjust
Volumetests 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'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.