Skip to content

fix(core): handle JSON parse failure gracefully in models-dev (fixes #29366)#29404

Open
levgiorg wants to merge 1 commit into
anomalyco:devfrom
levgiorg:fix/issue-29366-json-parse-fallback
Open

fix(core): handle JSON parse failure gracefully in models-dev (fixes #29366)#29404
levgiorg wants to merge 1 commit into
anomalyco:devfrom
levgiorg:fix/issue-29366-json-parse-fallback

Conversation

@levgiorg
Copy link
Copy Markdown

Issue for this PR

Closes #29366

Type of change

  • Bug fix

What does this PR do?

Wrap JSON.parse() in models-dev.ts in a try/catch so that network failures (e.g., HTML returned instead of JSON from blocked connections) don't crash opencode on startup. Returns {} on parse failure.

How did you verify your code works?

  • TypeScript typecheck passes
  • Existing tests pass

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions
Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

I found a potential duplicate:

PR #29385: fix(core): add fallback for JSON parse errors in models-dev
#29385

This PR appears to address the same issue as PR #29404 - handling JSON parse failures in the models-dev file. Both PRs are tackling the same problem of gracefully handling parse errors (likely from network failures returning HTML instead of JSON) and providing fallback behavior.

@shutaozhenzhen
Copy link
Copy Markdown

This PR seems to be missing the part that prints out the error?

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.

return {} on json parse error

2 participants