Skip to content

Commit df2b777

Browse files
committed
fix: resolve API failures being misclassified as user cancellations (#5427)
- Fixed error handling logic in Task.ts to check abort status before calling abortTask() - Ensures API failures show proper error messages instead of 'API Request Cancelled' - Addresses issue where all API failures on Windows were incorrectly categorized as user cancellations
1 parent 5b1ca51 commit df2b777

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/core/task/Task.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,20 +1422,21 @@ export class Task extends EventEmitter<ClineEvents> {
14221422
// Cline instance to finish aborting (error is thrown here when
14231423
// any function in the for loop throws due to this.abort).
14241424
if (!this.abandoned) {
1425+
// Check if this was a user-initiated cancellation BEFORE calling abortTask()
1426+
// If this.abort is true, it means the user clicked cancel, so we should
1427+
// treat this as "user_cancelled" rather than "streaming_failed"
1428+
const wasUserCancelled = this.abort
1429+
const cancelReason = wasUserCancelled ? "user_cancelled" : "streaming_failed"
1430+
const streamingFailedMessage = wasUserCancelled
1431+
? undefined
1432+
: (error.message ?? JSON.stringify(serializeError(error), null, 2))
1433+
14251434
// If the stream failed, there's various states the task
14261435
// could be in (i.e. could have streamed some tools the user
14271436
// may have executed), so we just resort to replicating a
14281437
// cancel task.
14291438
this.abortTask()
14301439

1431-
// Check if this was a user-initiated cancellation
1432-
// If this.abort is true, it means the user clicked cancel, so we should
1433-
// treat this as "user_cancelled" rather than "streaming_failed"
1434-
const cancelReason = this.abort ? "user_cancelled" : "streaming_failed"
1435-
const streamingFailedMessage = this.abort
1436-
? undefined
1437-
: (error.message ?? JSON.stringify(serializeError(error), null, 2))
1438-
14391440
await abortStream(cancelReason, streamingFailedMessage)
14401441

14411442
const history = await provider?.getTaskWithId(this.taskId)
@@ -1716,7 +1717,9 @@ export class Task extends EventEmitter<ClineEvents> {
17161717

17171718
const contextWindow = modelInfo.contextWindow
17181719

1719-
const currentProfileId = state?.listApiConfigMeta.find((profile) => profile.name === state?.currentApiConfigName)?.id ?? "default";
1720+
const currentProfileId =
1721+
state?.listApiConfigMeta.find((profile) => profile.name === state?.currentApiConfigName)?.id ??
1722+
"default"
17201723

17211724
const truncateResult = await truncateConversationIfNeeded({
17221725
messages: this.apiConversationHistory,

0 commit comments

Comments
 (0)