fix(provider): don't crash Provider.list when Cloudflare token missing - #42746
Open
SeashoreShi wants to merge 2 commits into
Open
fix(provider): don't crash Provider.list when Cloudflare token missing#42746SeashoreShi wants to merge 2 commits into
SeashoreShi wants to merge 2 commits into
Conversation
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 #42739
Type of change
What does this PR do?
Provider.listcrashes with an unhandled error when Cloudflare AI Gateway env vars (CLOUDFLARE_ACCOUNT_ID+CLOUDFLARE_GATEWAY_ID) are present but no API token is set:The
cloudflare-ai-gatewayloader throws directly when the token is missing, which propagates out ofProvider.listand takes down the whole server/TUI on startup. Every other missing-credential path in this file (e.g. missing account/gateway IDs) already returns{ autoload: false, getModel() { throw ... } }, deferring the error until the provider is actually used.This change makes the missing-token path consistent: the provider is listed as unavailable (
autoload: false) and the clear error only surfaces when a model is actually requested through it.Changes:
packages/opencode/src/provider/provider.ts: return{ autoload: false, getModel() { throw ... } }instead of throwing during provider loading when the Cloudflare token is missing.How did you verify your code works?
bun test test/provider/provider.test.ts: 100 pass, 0 fail (includes the existing cloudflare-ai-gateway tests, which still pass).Checklist