refactor(core): improve error handling and quota detection#2458
refactor(core): improve error handling and quota detection#2458tanzhenxin merged 2 commits intomainfrom
Conversation
- Move getErrorStatus from retry.ts to errors.ts for better organization - Add getErrorType utility to extract error class/category names - Enhance getErrorMessage to include cause chain for better debugging - Refactor ApiErrorEvent to use options object pattern (more readable) - Rename 'error' to 'error_message' in ApiErrorEvent for clarity - Make isQwenQuotaExceededError more precise: requires status=429, code='insufficient_quota', and 'free allocated quota exceeded' message - Update all tests to match new error detection behavior This improves error telemetry and makes quota detection more reliable. Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
📋 Review SummaryThis PR refactors error handling utilities and improves Qwen quota detection precision. The changes are well-structured, moving 🔍 General Feedback
🎯 Specific Feedback🟡 High
🟢 Medium
🔵 Low
✅ Highlights
|
Code Coverage Summary
CLI Package - Full Text ReportCore Package - Full Text ReportFor detailed HTML reports, please see the 'coverage-reports-22.x-ubuntu-latest' artifact from the main CI run. |
This aligns the test with the updated error handling that uses `status` instead of `code` for HTTP status codes. Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
TLDR
Refactors error handling utilities and makes Qwen quota detection more precise. The
isQwenQuotaExceededErrorfunction now requires exact matching of status code (429), error code (insufficient_quota), and message content (free allocated quota exceeded) to distinguish free-tier quota exhaustion from temporary throttling or paid account limits.Dive Deeper
This PR addresses the need for more reliable error detection and telemetry:
Error utilities consolidation: Moved
getErrorStatusfromretry.tstoerrors.tswhere it belongs alongside other error handling utilities.New
getErrorTypeutility: Extracts the error class name (e.g.,APIConnectionError,RateLimitError) which is more specific than generic.typefields. Also appends cause codes for network errors (e.g.,APIConnectionError:ECONNREFUSED).Enhanced
getErrorMessage: Now includes the cause chain when present, providing better debugging context for nested errors.ApiErrorEventrefactoring: Changed from positional constructor parameters to an options object pattern for better readability and maintainability. Renamederrortoerror_messagefor clarity.Precise quota detection: The
isQwenQuotaExceededErrorfunction now strictly matches:insufficient_quotafree allocated quota exceededThis prevents false positives from temporary throttling (concurrency 429s) or paid account quota limits.
Reviewer Test Plan
Run the affected tests:
Verify error detection works correctly by checking the test cases in
quotaErrorDetection.test.ts- they demonstrate the new precise matching behavior.Check that telemetry logs correctly capture error types and messages by examining the
ApiErrorEventconstruction inloggingContentGenerator.ts.Testing Matrix
Linked issues / bugs
Related to #2426 - This PR improves the error detection for quota-related errors, making it easier to distinguish between different types of rate limiting and quota exhaustion scenarios.
🤖 Generated with Qwen Code