Skip to content

Conversation

anson627
Copy link

@anson627 anson627 commented Jul 18, 2025

This pull request introduces improvements to error handling and message sequence validation in the src/lib/error.ts and src/routes/messages/non-stream-translation.ts files. The main changes include enhancing error response processing, adding helper functions for validating and fixing message sequences, and ensuring message consistency during translation.

Error Handling Improvements:

  • Enhanced the forwardError function in src/lib/error.ts to handle error responses more robustly by cloning the response and attempting to parse both JSON and text formats. This ensures better error logging and fallback mechanisms when parsing fails.

Message Sequence Validation and Fixing:

  • Added validateMessageSequence and fixMessageSequence helper functions in src/routes/messages/non-stream-translation.ts to ensure that all tool calls in a message sequence have corresponding responses. Missing responses are automatically added as placeholders.

Translation Enhancements:

  • Updated the translateToOpenAI function to integrate fixMessageSequence, ensuring that translated messages are validated and corrected for consistency before being returned.
  • Refactored the translateAnthropicMessagesToOpenAI function to use a more explicit loop for processing messages, improving readability and maintainability.Improved error response logging in src/lib/error.ts Added message sequence validation/fix for tool calls in src/routes/messages/non-stream-translation.ts

🤖 Generated with Claude Code

this is attempt to fix issue #62

Improved error response logging in src/lib/error.ts
Added message sequence validation/fix for tool calls in src/routes/messages/non-stream-translation.ts

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@huiqiangyang
Copy link

👍👍👍

@ericc-ch
Copy link
Owner

I'll be honest haven't had much time maintaining this project.
Have you tried it locally and confirm if it fixes the issue?

@anson627
Copy link
Author

anson627 commented Jul 21, 2025

after some testing, I found the error logging part is improved, but the issue is completely fixed, this is the new error I got
⎿ API Error: 400 {"error":{"message":"{"error":{"message":"messages.18.content.2: unexpected tool_use_id found in
tool_result blocks: toolu_vrtx_012G5RsC3QGHHU58HruL8XUt. Each tool_result block must have a corresponding tool_use block in
the previous message.","code":"invalid_request_body"}}","type":"error"}}

when I chose "No, and tell Claude what to do differently " after the initial prompt, need do some more debugging and try further fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants