Skip to content

Commit f877740

Browse files
committed
refactor: improve error handling for empty conversation history
- Initialize empty arrays for modified user content and API conversation history - Change error throw to debug log when no conversation history exists
1 parent 3d3d581 commit f877740

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/core/Cline.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,8 @@ export class Cline {
598598

599599
let modifiedOldUserContent: UserContent // either the last message if its user message, or the user message before the last (assistant) message
600600
let modifiedApiConversationHistory: Anthropic.Messages.MessageParam[] // need to remove the last user message to replace with new modified user message
601+
modifiedOldUserContent = []
602+
modifiedApiConversationHistory = []
601603
if (existingApiConversationHistory.length > 0) {
602604
const lastMessage = existingApiConversationHistory[existingApiConversationHistory.length - 1]
603605

@@ -667,7 +669,7 @@ export class Cline {
667669
throw new Error("Unexpected: Last message is not a user or assistant message")
668670
}
669671
} else {
670-
throw new Error("Unexpected: No existing API conversation history")
672+
console.debug(Error("Unexpected: No existing API conversation history"))
671673
}
672674

673675
let newUserContent: UserContent = [...modifiedOldUserContent]

0 commit comments

Comments
 (0)