Skip to content

Fix: Improve error handling in readConfig() to distinguish read vs parse errors#45

Open
hobostay wants to merge 1 commit into
1st1:mainfrom
hobostay:fix/error-type-in-config-read
Open

Fix: Improve error handling in readConfig() to distinguish read vs parse errors#45
hobostay wants to merge 1 commit into
1st1:mainfrom
hobostay:fix/error-type-in-config-read

Conversation

@hobostay

Copy link
Copy Markdown

Problem

The readConfig() function in src/config.ts had imprecise error handling. All errors were reported as "failed to parse config", even when the actual error was a file system issue (e.g., permission denied, file is a directory, I/O error) that occurred during readFileSync().

This made it difficult for users to diagnose configuration issues - a permission problem would be reported as a parse error, leading to confusion.

Solution

Split the error handling into two distinct stages:

  1. File read stage - First, read the file content using readFileSync(). Any errors at this stage (file system issues) are now reported as "failed to read config".
  2. JSON parse stage - Then, parse the JSON content. Any errors at this stage are reported as "failed to parse config".

Changes

  • src/config.ts: Modified readConfig() to separate file reading from JSON parsing
  • Error messages now correctly distinguish between:
    • "Error: failed to read config..." (file system issues)
    • "Error: failed to parse config..." (invalid JSON)

Testing

  • All existing tests pass (155 tests)
  • The change maintains backward compatibility - the same errors are still caught and reported, just with more accurate messages

Co-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com

…rse errors

Previously, readConfig() would report all errors as "failed to parse",
even if the actual error was a file system issue (permission denied,
file is a directory, etc.) during readFileSync().

This change splits the error handling into two stages:
1. First, read the file content - errors are reported as "failed to read"
2. Then, parse the JSON - errors are reported as "failed to parse"

This provides more accurate error messages to help users diagnose
configuration issues.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Mar 29, 2026

Copy link
Copy Markdown

@hobostay is attempting to deploy a commit to the Yury Selivanov's projects Team on Vercel.

A member of the Team first needs to authorize it.

Comment thread src/config.ts
process.stderr.write(
`Error: failed to read config ${configPath}: ${(err as Error).message}\n`,
);
process.exit(1);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you throw an error instead of exit in order to be consistent with getLlmKey below?

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