From 575cfd48cc204f74c30bdc8fb584fe95f7b98dbd Mon Sep 17 00:00:00 2001 From: Bee <68532117+abeatrix@users.noreply.github.com> Date: Mon, 14 Jul 2025 22:16:50 -0700 Subject: [PATCH] Includes request ID in error returned by Cline API (#4909) * Includes request ID in error returned by Cline API Adding the request ID to error messages to aid in debugging for users. * Use constant for auth error message; revert change from previous PR * Fix webview auth status if null/undefined user is passed in auth status message * Create nasty-parents-play.md --------- Co-authored-by: abeatrix Co-authored-by: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com> --- .changeset/nasty-parents-play.md | 5 +++++ src/api/providers/cline.ts | 21 ++++++++++++------- src/shared/ClineAccount.ts | 3 +++ webview-ui/src/components/chat/ChatRow.tsx | 5 ++--- .../src/components/chat/CreditLimitError.tsx | 2 +- webview-ui/src/context/ClineAuthContext.tsx | 8 +++++-- 6 files changed, 31 insertions(+), 13 deletions(-) create mode 100644 .changeset/nasty-parents-play.md diff --git a/.changeset/nasty-parents-play.md b/.changeset/nasty-parents-play.md new file mode 100644 index 00000000..aad9542a --- /dev/null +++ b/.changeset/nasty-parents-play.md @@ -0,0 +1,5 @@ +--- +"claude-dev": patch +--- + +Includes request ID in error returned by Cline API diff --git a/src/api/providers/cline.ts b/src/api/providers/cline.ts index dee0e7da..34b0422e 100644 --- a/src/api/providers/cline.ts +++ b/src/api/providers/cline.ts @@ -11,6 +11,7 @@ import { AuthService } from "@/services/auth/AuthService" import OpenAI from "openai" import { version as extensionVersion } from "../../../package.json" import { shouldSkipReasoningForModel } from "@utils/model-utils" +import { CLINE_ACCOUNT_AUTH_ERROR_MESSAGE } from "@/shared/ClineAccount" interface ClineHandlerOptions { taskId?: string @@ -42,7 +43,7 @@ export class ClineHandler implements ApiHandler { private async ensureClient(): Promise { const clineAccountAuthToken = await this._authService.getAuthToken() if (!clineAccountAuthToken) { - throw new Error("Cline account authentication token is required") + throw new Error(CLINE_ACCOUNT_AUTH_ERROR_MESSAGE) } if (!this.client) { try { @@ -183,13 +184,19 @@ export class ClineHandler implements ApiHandler { } } } catch (error) { - if (error.code === "ERR_BAD_REQUEST" || error.status === 401) { - throw new Error("Unauthorized: Please sign in to Cline before trying again.") // match with webview-ui/src/components/chat/ChatRow.tsx - } else if (error.code === "insufficient_credits" || error.status === 402) { - throw new Error(error.error ? JSON.stringify(error.error) : "Insufficient credits or unknown error.") - } console.error("Cline API Error:", error) - throw error instanceof Error ? error : new Error(String(error)) + const requestId = error?.request_id ? ` (Request ID: ${error.request_id})` : "" + if (error.code === "ERR_BAD_REQUEST" || error.status === 401) { + throw new Error(CLINE_ACCOUNT_AUTH_ERROR_MESSAGE + requestId) + } else if (error.code === "insufficient_credits" || error.status === 402) { + if (error.error) { + error.error.message = error.error.message + requestId + throw new Error(JSON.stringify(error.error)) + } + } + const _error = error instanceof Error ? error : new Error(String(error)) + _error.message = _error.message + requestId + throw _error } } diff --git a/src/shared/ClineAccount.ts b/src/shared/ClineAccount.ts index 5d1cd5d5..72371805 100644 --- a/src/shared/ClineAccount.ts +++ b/src/shared/ClineAccount.ts @@ -76,3 +76,6 @@ export interface OrganizationUsageTransaction { totalTokens: number userId: string } + +// Used in cline.ts provider and in webview-ui/src/components/chat/ChatRow.tsx to display the login button +export const CLINE_ACCOUNT_AUTH_ERROR_MESSAGE = "Unauthorized: Please sign in to Cline before trying again." diff --git a/webview-ui/src/components/chat/ChatRow.tsx b/webview-ui/src/components/chat/ChatRow.tsx index ea0e8577..42379d6a 100644 --- a/webview-ui/src/components/chat/ChatRow.tsx +++ b/webview-ui/src/components/chat/ChatRow.tsx @@ -37,6 +37,7 @@ import ReportBugPreview from "./ReportBugPreview" import UserMessage from "./UserMessage" import QuoteButton from "./QuoteButton" import { useClineAuth } from "@/context/ClineAuthContext" +import { CLINE_ACCOUNT_AUTH_ERROR_MESSAGE } from "@shared/ClineAccount" const normalColor = "var(--vscode-foreground)" const errorColor = "var(--vscode-errorForeground)" @@ -1008,9 +1009,7 @@ export const ChatRowContent = memo( . )} - {apiRequestFailedMessage?.includes( - "Unauthorized: Please sign in to Cline before trying again.", // match with cline.ts (TODO: remove after some time) - ) && ( + {apiRequestFailedMessage?.includes(CLINE_ACCOUNT_AUTH_ERROR_MESSAGE) && ( <>

diff --git a/webview-ui/src/components/chat/CreditLimitError.tsx b/webview-ui/src/components/chat/CreditLimitError.tsx index 2b9cf9c2..e2d09acd 100644 --- a/webview-ui/src/components/chat/CreditLimitError.tsx +++ b/webview-ui/src/components/chat/CreditLimitError.tsx @@ -25,7 +25,7 @@ const CreditLimitError: React.FC = ({
{message}
- Current Balance: ${(currentBalance / 1000000).toFixed(4)} + Current Balance: ${currentBalance.toFixed(4)}
diff --git a/webview-ui/src/context/ClineAuthContext.tsx b/webview-ui/src/context/ClineAuthContext.tsx index dfe3068e..d7c02eb1 100644 --- a/webview-ui/src/context/ClineAuthContext.tsx +++ b/webview-ui/src/context/ClineAuthContext.tsx @@ -30,8 +30,12 @@ export const ClineAuthProvider: React.FC<{ children: React.ReactNode }> = ({ chi const cancelSubscription = AccountServiceClient.subscribeToAuthStatusUpdate(EmptyRequest.create(), { onResponse: async (response: any) => { console.log("Extension: ClineAuthContext: Received auth status update:", response) - if (response && response.user) { - setUser(response.user) + if (response) { + if (response.user) { + setUser(response.user) + } else { + setUser(null) + } } }, onError: (error: Error) => {