fix: graceful ENOENT error when DESIGN.md is missing (#132)#145
Open
Emp1500 wants to merge 2 commits into
Open
fix: graceful ENOENT error when DESIGN.md is missing (#132)#145Emp1500 wants to merge 2 commits into
Emp1500 wants to merge 2 commits into
Conversation
… stderr (google-labs-code#132) Introduce a typed `FileReadError` class in `readInput` so the function throws instead of calling `process.exit` directly. Each command handler catches it and writes a plain-text error to stderr: Error: "DESIGN.md" not found. Create a DESIGN.md file or pass "-" to read from stdin. This replaces the unhandled Node.js stack trace dump reported in google-labs-code#132. `readInput` is now unit-testable without mocking `process.exit`, and `FileReadError.filePath` identifies the specific missing file (important for `diff`, which reads two files).
Replace the hardcoded "not found" string in all command handlers with a friendlyMessage getter on FileReadError that checks the OS error code: - ENOENT → "not found. Create a DESIGN.md file or pass '-' for stdin." - EACCES → "could not be read: permission denied." - other → "could not be read: <raw message>" This prevents a misleading "not found" message when the file exists but cannot be read due to permissions or other I/O errors.
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.
fix(cli): graceful error on missing or unreadable input file
##Before
ERROR ENOENT: no such file or directory, open 'DESIGN.md'
at readFileSync (node:fs:441:20)
at readInput (...index.js:24123:12)
##After
File missing:
Error: "DESIGN.md" not found. Create a DESIGN.md file or pass "-" to read from stdin.
Permission denied:
Error: "DESIGN.md" could not be read: permission denied.
Any other I/O error:
Error: "DESIGN.md" could not be read:
##Solution
Introduces a typed FileReadError class. readInput now throws it instead of calling process.exit directly. A friendlyMessage getter on the class checks the underlying OS error code
(ENOENT, EACCES, etc.) to produce an accurate message — so the error never says "not found" when the real problem is permissions.
Each command catches FileReadError, writes the plain-text message to stderr, and exits with code 2.
##Why this approach is better than a plain process.exit wrap:
##Changes
Fixes #132