* Unify error handling and display Several improvements to error handling and reporting within the Cline extension, focusing on providing more informative error messages to the user and improving telemetry data. - **Error Handling:** - Introduces a `ClineError` class to encapsulate Cline-specific errors, providing structured data about the error (status code, request ID, etc.). - The `ErrorService` now creates and logs `ClineError` instances, improving error reporting to Sentry and telemetry. - Removes redundant error formatting logic from `src/core/task/utils.ts`, relying on the `ClineError` class for consistent error representation. - The Cline API handler now throws the raw error, allowing the `ClineError` class to handle the error formatting. - **UI Improvements:** - Introduces new UI components (`ErrorRow`, `ErrorBlockTitle`) to display error messages in a more user-friendly format within the chat interface. - Displays credit limit errors with detailed information and a link to purchase credits. - Improves the display of rate limit errors and authentication errors. - Adds specific handling for PowerShell-related errors, providing a link to a troubleshooting guide. - **Telemetry:** - Captures provider API errors using `ClineError` data, providing more detailed information about the error in telemetry reports. - **Other Changes:** - Fixes an import path in `src/services/posthog/PostHogClientProvider.ts`. - Adds tests for the new UI components. - Adds `error` field to `ClineMessage` to transport `ClineError` instances to the webview. These changes aim to provide a better user experience by displaying more informative error messages and improving the overall reliability of the Cline extension. * include provider id * includes model and provider id * fix test * return gracefully for empty response
107 lines
3.3 KiB
TypeScript
107 lines
3.3 KiB
TypeScript
import React from "react"
|
|
import { ClineError, ClineErrorType } from "../../../../src/services/error/ClineError"
|
|
import { ProgressIndicator } from "./ChatRow"
|
|
|
|
const RetryMessage = React.memo(
|
|
({ seconds, attempt, retryOperations }: { retryOperations: number; attempt: number; seconds?: number }) => {
|
|
const [remainingSeconds, setRemainingSeconds] = React.useState(seconds || 0)
|
|
|
|
React.useEffect(() => {
|
|
if (seconds && seconds > 0) {
|
|
setRemainingSeconds(seconds)
|
|
|
|
const interval = setInterval(() => {
|
|
setRemainingSeconds((prev) => {
|
|
if (prev <= 1) {
|
|
clearInterval(interval)
|
|
return 0
|
|
}
|
|
return prev - 1
|
|
})
|
|
}, 1000)
|
|
|
|
return () => clearInterval(interval)
|
|
}
|
|
}, [seconds])
|
|
|
|
return (
|
|
<span className="font-bold text-[var(--vscode-foreground)]">
|
|
{`API Request (Retrying failed attempt ${attempt}/${retryOperations}`}
|
|
{remainingSeconds > 0 && ` in ${remainingSeconds} seconds`}
|
|
)...
|
|
</span>
|
|
)
|
|
},
|
|
)
|
|
|
|
interface ErrorBlockTitleProps {
|
|
cost?: number
|
|
apiReqCancelReason?: string
|
|
apiRequestFailedMessage?: string
|
|
retryStatus?: {
|
|
attempt: number
|
|
maxAttempts: number
|
|
delaySec?: number
|
|
errorSnippet?: string
|
|
}
|
|
}
|
|
|
|
export const ErrorBlockTitle = ({
|
|
cost,
|
|
apiReqCancelReason,
|
|
apiRequestFailedMessage,
|
|
retryStatus,
|
|
}: ErrorBlockTitleProps): [React.ReactElement, React.ReactElement] => {
|
|
const getIconSpan = (iconName: string, colorClass: string) => (
|
|
<div className="w-4 h-4 flex items-center justify-center">
|
|
<span className={`codicon codicon-${iconName} text-base -mb-0.5 ${colorClass}`}></span>
|
|
</div>
|
|
)
|
|
|
|
const icon =
|
|
apiReqCancelReason != null ? (
|
|
apiReqCancelReason === "user_cancelled" ? (
|
|
getIconSpan("error", "text-[var(--vscode-descriptionForeground)]")
|
|
) : (
|
|
getIconSpan("error", "text-[var(--vscode-errorForeground)]")
|
|
)
|
|
) : cost != null ? (
|
|
getIconSpan("check", "text-[var(--vscode-charts-green)]")
|
|
) : apiRequestFailedMessage ? (
|
|
getIconSpan("error", "text-[var(--vscode-errorForeground)]")
|
|
) : (
|
|
<ProgressIndicator />
|
|
)
|
|
|
|
const title = (() => {
|
|
// Default loading state
|
|
const details = { title: "API Request...", classNames: ["font-bold"] }
|
|
// Handle cancellation states first
|
|
if (apiReqCancelReason === "user_cancelled") {
|
|
details.title = "API Request Cancelled"
|
|
details.classNames.push("text-[var(--vscode-foreground)]")
|
|
} else if (apiReqCancelReason != null) {
|
|
details.title = "API Streaming Failed"
|
|
details.classNames.push("text-[var(--vscode-errorForeground)]")
|
|
} else if (cost != null) {
|
|
// Handle completed request
|
|
details.title = "API Request"
|
|
details.classNames.push("text-[var(--vscode-foreground)]")
|
|
} else if (apiRequestFailedMessage) {
|
|
// Handle failed request
|
|
const clineError = ClineError.parse(apiRequestFailedMessage)
|
|
const titleText = clineError?.isErrorType(ClineErrorType.Balance) ? "Credit Limit Reached" : "API Request Failed"
|
|
details.title = titleText
|
|
details.classNames.push("font-bold text-[var(--vscode-errorForeground)]")
|
|
} else if (retryStatus) {
|
|
// Handle retry state
|
|
const retryOperations = Math.max(0, retryStatus.maxAttempts - 1)
|
|
return <RetryMessage seconds={retryStatus.delaySec} attempt={retryStatus.attempt} retryOperations={retryOperations} />
|
|
}
|
|
|
|
return <span className={details.classNames.join(" ")}>{details.title}</span>
|
|
})()
|
|
|
|
return [icon, title]
|
|
}
|