fix(web): Address review findings for M4-LLM integration
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
ci/woodpecker/pr/woodpecker Pipeline was successful

- Sanitize user-facing error messages (no raw API/DB errors)
- Remove dead try/catch from Chat.tsx handleSendMessage
- Add onError callback for persistence errors in useChat
- Add console.error logging to loadConversation
- Guard minimize/toggleMinimize against closed overlay state
- Improve error dedup bucketing for non-DOMException errors
- Add tests: non-Error throws, updateConversation failure,
  minimize/toggleMinimize guards

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Jason Woltje
2026-02-06 20:25:03 -06:00
parent da1862816f
commit f64ca3871d
6 changed files with 130 additions and 28 deletions

View File

@@ -176,22 +176,19 @@ describe("Chat", () => {
});
});
describe("sendMessage error handling", () => {
it("should log error when sendMessage fails", async () => {
const sendError = new Error("Send failed");
const mockSendMessage = vi.fn().mockRejectedValue(sendError);
describe("sendMessage delegation", () => {
it("should delegate to useChat.sendMessage without extra error handling", async () => {
const mockSendMessage = vi.fn().mockResolvedValue(undefined);
mockUseChat.mockReturnValue(createMockUseChatReturn({ sendMessage: mockSendMessage }));
const ref = createRef<ChatRef>();
const { getByTestId } = render(<Chat ref={ref} />);
// Click the send button (which calls handleSendMessage)
const sendButton = getByTestId("chat-input");
sendButton.click();
// Wait for async handling
await vi.waitFor(() => {
expect(consoleSpy).toHaveBeenCalledWith("Error sending message:", sendError);
expect(mockSendMessage).toHaveBeenCalledWith("test message");
});
});
});

View File

@@ -73,9 +73,6 @@ export const Chat = forwardRef<ChatRef, ChatProps>(function Chat(
} = useChat({
model: "llama3.2",
...(initialProjectId !== undefined && { projectId: initialProjectId }),
onError: (_err) => {
// Error is handled by the useChat hook's state
},
});
// Connect to WebSocket for real-time updates (when we have a user)
@@ -180,11 +177,7 @@ export const Chat = forwardRef<ChatRef, ChatProps>(function Chat(
const handleSendMessage = useCallback(
async (content: string) => {
try {
await sendMessage(content);
} catch (err) {
console.error("Error sending message:", err);
}
await sendMessage(content);
},
[sendMessage]
);