fix(config): catch parse errors gracefully during startup#29208
Draft
HaleTom wants to merge 32 commits into
Draft
fix(config): catch parse errors gracefully during startup#29208HaleTom wants to merge 32 commits into
HaleTom wants to merge 32 commits into
Conversation
Wrap ConfigParse.jsonc() and ConfigParse.effectSchema() calls in
loadConfig with Effect.catchCause to prevent sync-thrown JsonError
and InvalidError from becoming Effect defects. On parse/schema
failure, the bad file is skipped with a log.error and {} fallback
instead of crashing, matching the existing tui.jsonc error handling
pattern in tui.ts.
Without this, any invalid JSONC syntax or schema violation in
opencode.json/opencode.jsonc causes "4 of 6 requests failed:
Unexpected server error" on startup. Now the server starts with
default values and logs the config error details.
Fixes anomalyco#29200
Contributor
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
Author
|
@gemini-code-review pls review |
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Updates config loading to be resilient to malformed config input (schema/JSON/JSONC) by logging errors and falling back to defaults, with accompanying test adjustments.
Changes:
- Wrap config expansion/parsing/schema validation (and related steps) in error handling that logs and returns an empty config object.
- Update tests to expect successful config resolution (no crash) for invalid schema and invalid JSON.
- Add tests for invalid JSONC and for merging when one config file is bad.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| packages/opencode/src/config/config.ts | Adds catch-and-fallback behavior during config variable substitution, JSONC parsing, schema validation, plugin resolution, and schema injection/write-back. |
| packages/opencode/test/config/config.test.ts | Reworks negative tests to assert non-crashing behavior and adds coverage for bad JSONC and multi-file merge behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
6 tasks
- Use safe fallback for Info decode ({} as Info) instead of Schema.decodeSync
- Use Cause.pretty for plugin resolution error logging
- Strengthen test assertion with specific value
- Strip unknown config keys before schema validation to preserve valid fields - Sanitize log.error calls to avoid leaking config content via cause - Handle plugin resolution per-item to avoid partial mutation on failure - Add test for plugin resolution failure
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.
Issue for this PR
Closes #29200
Closes #29041
Type of change
What does this PR do?
Invalid JSON or JSONC in
opencode.jsoncproduces "Unexpected server error" on startup.ConfigParse.jsonc()throwsJsonErrorandConfigParse.schema()throwsInvalidErroras plain exceptions, which become Effect defects insideEffect.genand propagate as generic HTTP 500s.Wraps the parsing/schema-validation steps in
Effect.syncwithEffect.catchCause(the correct operator for catching sync-thrown defects insideEffect.gen). On error, logs the cause server-side and returns an empty{}config viaSchema.decodeSync, so the server starts with defaults.How did you verify your code works?
Checklist