Repository navigation
fix(oauth): print fixed CLI login errors instead of provider bodies #7171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c15bc03
fix(oauth): print fixed CLI login errors instead of provider bodies
c5362aa
fix(oauth): keep standard error codes and namespace errors in CLI log…
f311c83
fix(oauth): report namespace collisions as configuration errors in login
b454abb
fix(oauth): classify wrapped xAI connection failures as network errors
b5873c7
fix(oauth): report Pool 2 preflight configuration failures safely
c0da7fd
fix(oauth): guard Pool 2 at the shared CLI entry point
4299692
Merge origin/dev into fix/oauth-cli-error-bodies
lidge-jun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { AnthropicTokenError } from "./anthropic"; | ||
| import { OAuthProviderNamespaceCollisionError, OAuthProviderPublicationError, publicOAuthAuthenticationErrorMessage } from "./index"; | ||
| import { XaiTokenRequestError } from "./xai"; | ||
| import { AnthropicInstanceCollisionError, AnthropicInstanceConfigReadError } from "./store-anthropic-instance"; | ||
|
|
||
| // Standard RFC 6749 / RFC 6750 / RFC 8628 error codes. A provider's `error` field is printed only | ||
| // when it is one of these, so a body that echoes request parameters there still prints nothing. | ||
| const STANDARD_OAUTH_ERROR_CODES = new Set([ | ||
| "invalid_request", "invalid_client", "invalid_grant", "unauthorized_client", | ||
| "unsupported_grant_type", "invalid_scope", "access_denied", "unsupported_response_type", | ||
| "server_error", "temporarily_unavailable", "invalid_token", "insufficient_scope", | ||
| "authorization_pending", "slow_down", "expired_token", | ||
| ]); | ||
|
|
||
| /** Fixed, machine-readable reason for a failed login; never derived from free-form text. */ | ||
| export function oauthLoginFailureDiagnostic(error: unknown): string { | ||
| if (error instanceof OAuthProviderNamespaceCollisionError || error instanceof OAuthProviderPublicationError | ||
| || error instanceof AnthropicInstanceCollisionError || error instanceof AnthropicInstanceConfigReadError) { | ||
| return "configuration_error"; | ||
| } | ||
| const status = error instanceof AnthropicTokenError ? error.httpStatus | ||
| : error instanceof XaiTokenRequestError ? error.status : undefined; | ||
| const oauthError = error instanceof AnthropicTokenError || error instanceof XaiTokenRequestError | ||
| ? error.oauthError : undefined; | ||
| const parts: string[] = []; | ||
| if (typeof status === "number" && Number.isInteger(status) && status >= 400 && status <= 599) parts.push(`HTTP ${status}`); | ||
| if (typeof oauthError === "string" && STANDARD_OAUTH_ERROR_CODES.has(oauthError)) parts.push(oauthError); | ||
| if (parts.length > 0) return parts.join(" "); | ||
| const name = error instanceof Error ? error.name : ""; | ||
| if (name === "TimeoutError" || name === "AbortError") return "timeout"; | ||
| // fetch() reports refused connections and DNS failures as a TypeError carrying a string code; a | ||
| // programming TypeError carries none and stays in the generic bucket. | ||
| const code = error instanceof TypeError ? (error as { code?: unknown }).code : undefined; | ||
| if ((error instanceof AnthropicTokenError && error.requestNotSent) | ||
| || (error instanceof XaiTokenRequestError && error.status === undefined) | ||
| || (typeof code === "string" && code !== "")) return "network_error"; | ||
| return "oauth_authentication_failed"; | ||
| } | ||
|
|
||
| /** Keep terminal login failures within the public OAuth error vocabulary. */ | ||
| export function reportOAuthLoginError(error: unknown): never { | ||
| console.error(`\n❌ OAuth login failed (${oauthLoginFailureDiagnostic(error)}): ${publicOAuthAuthenticationErrorMessage(error)}`); | ||
| process.exit(1); | ||
| } | ||
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.