fix: surface api_key/base_url resolution errors instead of discarding them#3292
Open
albatrossflyon-coder wants to merge 1 commit into
Open
Conversation
… them
buildProvider discarded the error from c.cfg.Resolve() for both
api_key and base_url with the blank identifier, so a malformed
template, a failed $(command) substitution, or a required
${VAR:?message} check firing all failed silently. The provider would
then be built with an empty/wrong value, and any resulting auth
failure surfaced far from the actual root cause deep inside the
provider's own request path instead of at config load time.
Note: this intentionally does not add a blanket "empty api_key is
invalid" check — Bedrock (AWS credentials/profile) and Azure OpenAI
with Entra ID both legitimately have no api_key, and crush's config
resolver already supports opting into a hard failure per-provider via
${VAR:?message} syntax in the provider's own api_key template. The
bug is specifically the discarded resolution error, not missing
key-emptiness validation.
Fixes charmbracelet#3011
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.
Summary
buildProviderdiscarded the error fromc.cfg.Resolve()for bothapi_keyandbase_urlwith the blank identifier (apiKey, _ := ...)\$(command)substitution, or a required\${VAR:?message}check firing all failed silently — the provider was then built with an empty/wrong value, and the resulting auth failure surfaced far from the real root cause, deep inside the provider's own request path instead of at config load timeDeliberately scoped narrower than the issue's literal suggestion: the issue proposes failing whenever
api_keyresolves to empty, but that would be a real regression — Bedrock (AWS credential/profile auth) and Azure OpenAI with Entra ID both legitimately have noapi_keyconfigured. crush's resolver already supports opting into a hard failure per-provider via\${VAR:?message}syntax in the provider's ownapi_keytemplate (documented ininternal/config/resolve.go), so the actual bug here is the discarded resolution error, not missing empty-string validation.Fixes #3011
Test plan
go build ./...go test ./internal/agent/...— all pass, no regressions (pre-existing unrelated Windows path-separator failure ininternal/agent/toolsconfirmed present on unmodifiedmaintoo)TestBuildProviderSurfacesResolveErrors— confirms bothapi_keyandbase_urlresolution failures (via\${VAR:?message}) now return an error naming the field and provider, instead of silently proceedingp/security-audit,p/secrets,p/golang, Trail of Bits Go rules) on the changed files — 0 findings