Skip to content

Commit 0842045

Browse files
committed
[Nebula] Remove presence message when adding an error message (#5711)
Fixes: DASH-614 <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on improving error handling in the `setMessages` function within the `ChatPageContent` component. It modifies how error messages are added to the message list, ensuring that the previous messages are preserved correctly. ### Detailed summary - Refactored `setMessages` to create a new array `newMessages` based on previous messages. - Added a condition to exclude the last message if its type is "presence". - Pushed a new error message object containing the error details to `newMessages`. - Returned `newMessages` from `setMessages`. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 611ed23 commit 0842045

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

apps/dashboard/src/app/nebula-app/(app)/components/ChatPageContent.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,21 @@ export function ChatPageContent(props: {
242242
return;
243243
}
244244
console.error(error);
245-
setMessages((prev) => [
246-
...prev,
247-
{
245+
246+
setMessages((prev) => {
247+
const newMessages = prev.slice(
248+
0,
249+
prev[prev.length - 1]?.type === "presence" ? -1 : undefined,
250+
);
251+
252+
// add error message
253+
newMessages.push({
248254
text: `Error: ${error instanceof Error ? error.message : "Failed to execute command"}`,
249255
type: "error",
250-
},
251-
]);
256+
});
257+
258+
return newMessages;
259+
});
252260
} finally {
253261
setIsChatStreaming(false);
254262
}

0 commit comments

Comments
 (0)