Skip to content

fix(provider): don't crash Provider.list when Cloudflare token missing - #42746

Open
SeashoreShi wants to merge 2 commits into
anomalyco:devfrom
SeashoreShi:fix/cloudflare-token-missing-list-crash
Open

fix(provider): don't crash Provider.list when Cloudflare token missing#42746
SeashoreShi wants to merge 2 commits into
anomalyco:devfrom
SeashoreShi:fix/cloudflare-token-missing-list-crash

Conversation

@SeashoreShi

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #42739

Type of change

  • Bug fix

What does this PR do?

Provider.list crashes with an unhandled error when Cloudflare AI Gateway env vars (CLOUDFLARE_ACCOUNT_ID + CLOUDFLARE_GATEWAY_ID) are present but no API token is set:

Error: CLOUDFLARE_API_TOKEN (or CF_AIG_TOKEN) is required for Cloudflare AI Gateway...
    at Provider.list ...

The cloudflare-ai-gateway loader throws directly when the token is missing, which propagates out of Provider.list and 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?

  • Ran bun test test/provider/provider.test.ts: 100 pass, 0 fail (includes the existing cloudflare-ai-gateway tests, which still pass).
  • The new behavior mirrors the already-tested missing-ID path in the same loader.

Checklist

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Unhandled crash in Provider.list when Cloudflare environment variables exist without CLOUDFLARE_API_TOKEN

1 participant