fix: log auth profile resolution failures instead of swallowing silently#41271
Conversation
Greptile SummaryThis PR fixes silent error swallowing in the auth-profile candidate loop inside
Confidence Score: 5/5
Last reviewed commit: cb13e91 |
| @@ -221,7 +224,9 @@ export async function resolveApiKeyForProvider(params: { | |||
| mode: mode === "oauth" ? "oauth" : mode === "token" ? "token" : "api-key", | |||
| }; | |||
| } | |||
| } catch {} | |||
| } catch (err) { | |||
| log.debug?.(`auth profile "${candidate}" failed for provider "${provider}": ${String(err)}`); | |||
There was a problem hiding this comment.
Unnecessary optional chaining on log.debug
debug is always present on SubsystemLogger — the type definition in src/logging/subsystem.ts declares it as a required (non-optional) method, and every instance created by createSubsystemLogger always assigns it. Using ?. here is therefore superfluous and inconsistent with every other log.debug(...) call in the codebase (e.g. src/memory/manager-sync-ops.ts, src/hooks/bundled/session-memory/handler.ts, etc.).
| log.debug?.(`auth profile "${candidate}" failed for provider "${provider}": ${String(err)}`); | |
| log.debug(`auth profile "${candidate}" failed for provider "${provider}": ${String(err)}`); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/model-auth.ts
Line: 228
Comment:
**Unnecessary optional chaining on `log.debug`**
`debug` is always present on `SubsystemLogger` — the type definition in `src/logging/subsystem.ts` declares it as a required (non-optional) method, and every instance created by `createSubsystemLogger` always assigns it. Using `?.` here is therefore superfluous and inconsistent with every other `log.debug(...)` call in the codebase (e.g. `src/memory/manager-sync-ops.ts`, `src/hooks/bundled/session-memory/handler.ts`, etc.).
```suggestion
log.debug(`auth profile "${candidate}" failed for provider "${provider}": ${String(err)}`);
```
How can I resolve this? If you propose a fix, please make it concise.07d4f32 to
64b3950
Compare
When resolveApiKeyForProvider iterates auth profiles and each one throws (e.g., OAuth token refresh fails, keychain access denied, corrupted credential file), the errors are silently swallowed. If all profiles fail, the user gets a misleading "No API key found" error suggesting they haven't configured auth at all. Add debug-level logging so `--debug` output reveals the real failure reason for each profile candidate. This matches the logging pattern used in auth-profiles/oauth.ts for similar error paths.
64b3950 to
049d1e1
Compare
|
Merged via squash.
Thanks @he-yufeng! |
…tly (openclaw#41271) Merged via squash. Prepared head SHA: 049d1e1 Co-authored-by: he-yufeng <40085740+he-yufeng@users.noreply.github.com> Co-authored-by: altaywtf <9790196+altaywtf@users.noreply.github.com> Reviewed-by: @altaywtf
…tly (openclaw#41271) Merged via squash. Prepared head SHA: 049d1e1 Co-authored-by: he-yufeng <40085740+he-yufeng@users.noreply.github.com> Co-authored-by: altaywtf <9790196+altaywtf@users.noreply.github.com> Reviewed-by: @altaywtf
…tly (openclaw#41271) Merged via squash. Prepared head SHA: 049d1e1 Co-authored-by: he-yufeng <40085740+he-yufeng@users.noreply.github.com> Co-authored-by: altaywtf <9790196+altaywtf@users.noreply.github.com> Reviewed-by: @altaywtf
…tly (openclaw#41271) Merged via squash. Prepared head SHA: 049d1e1 Co-authored-by: he-yufeng <40085740+he-yufeng@users.noreply.github.com> Co-authored-by: altaywtf <9790196+altaywtf@users.noreply.github.com> Reviewed-by: @altaywtf
…tly (openclaw#41271) Merged via squash. Prepared head SHA: 049d1e1 Co-authored-by: he-yufeng <40085740+he-yufeng@users.noreply.github.com> Co-authored-by: altaywtf <9790196+altaywtf@users.noreply.github.com> Reviewed-by: @altaywtf
…tly (openclaw#41271) Merged via squash. Prepared head SHA: 049d1e1 Co-authored-by: he-yufeng <40085740+he-yufeng@users.noreply.github.com> Co-authored-by: altaywtf <9790196+altaywtf@users.noreply.github.com> Reviewed-by: @altaywtf
…tly (openclaw#41271) Merged via squash. Prepared head SHA: 049d1e1 Co-authored-by: he-yufeng <40085740+he-yufeng@users.noreply.github.com> Co-authored-by: altaywtf <9790196+altaywtf@users.noreply.github.com> Reviewed-by: @altaywtf
…tly (openclaw#41271) Merged via squash. Prepared head SHA: 049d1e1 Co-authored-by: he-yufeng <40085740+he-yufeng@users.noreply.github.com> Co-authored-by: altaywtf <9790196+altaywtf@users.noreply.github.com> Reviewed-by: @altaywtf
Summary
When
resolveApiKeyForProvideriterates through auth profile candidates (line 207-225 insrc/agents/model-auth.ts), each failed resolution is silently swallowed by a barecatch {}. If all profiles fail — due to OAuth token refresh errors, keychain access issues, corrupted credential files, or network problems — the user gets a misleading error:This suggests they haven't configured auth, when the real issue might be a temporary failure that a retry would fix.
Note the contrast with line 177-185 in the same function: when a specific profile is requested, failures properly propagate. Only the auto-discovery loop swallows errors.
What changed
Added debug-level logging for each failed profile resolution attempt:
Users can see these with
--debugoutput to diagnose why auth isn't working. This matches the logging pattern already used inauth-profiles/oauth.tsfor similar error paths.Test plan
--debugoutput shows the specific failure for each candidate