Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/core/task/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -686,14 +686,18 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
// saves, and only post parts of partial message instead of
// whole array in new listener.
this.updateClineMessage(lastMessage)
throw new Error("Current ask promise was ignored (#1)")
// This is expected behavior when updating a partial message
// Silently return to avoid confusing error messages
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says "Silently return" but we're actually rejecting with an error. Would "Return rejected promise with descriptive message" be more accurate?

return Promise.reject(new Error("Partial message update - expected behavior"))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this pattern of using return Promise.reject() instead of throw new Error() consistent with the rest of the codebase? Both are functionally equivalent in async contexts, but consistency matters.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using a structured prefix like "[EXPECTED]" instead of the suffix " - expected behavior" for easier parsing by monitoring tools:

Suggested change
return Promise.reject(new Error("Partial message update - expected behavior"))
return Promise.reject(new Error("[EXPECTED] Partial message update"))

} else {
// This is a new partial message, so add it with partial
// state.
askTs = Date.now()
this.lastMessageTs = askTs
await this.addToClineMessages({ ts: askTs, type: "ask", ask: type, text, partial, isProtected })
throw new Error("Current ask promise was ignored (#2)")
// This is expected behavior when creating a new partial message
// Silently return to avoid confusing error messages
return Promise.reject(new Error("New partial message - expected behavior"))
}
} else {
if (isUpdatingPreviousPartial) {
Expand Down Expand Up @@ -797,7 +801,9 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
// Could happen if we send multiple asks in a row i.e. with
// command_output. It's important that when we know an ask could
// fail, it is handled gracefully.
throw new Error("Current ask promise was ignored")
// This is expected behavior when multiple asks are sent in sequence
// Silently reject to avoid confusing error messages
return Promise.reject(new Error("Ask promise superseded - expected behavior"))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Future consideration: While marking these as "expected behavior" helps AI models, we're still using error throwing for control flow. Worth exploring alternative patterns like special return values or a different control mechanism in a future refactor?

}

const result = { response: this.askResponse!, text: this.askResponseText, images: this.askResponseImages }
Expand Down
Loading