-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix: exit with non-zero code on API errors in text mode #1376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
📋 Review SummaryThis PR fixes an important issue where the Qwen CLI would exit with code 0 even when API errors occurred in text mode. The fix involves throwing an error after writing the error message to stderr, ensuring the process exits with a non-zero code. The PR also includes a comprehensive test case to verify the fix. 🔍 General Feedback
🎯 Specific Feedback🟢 Medium
✅ 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. |
TLDR
When API errors occur (e.g., 401 Incorrect API key), the Qwen CLI process exits with code 0 instead of a non-zero exit code. This makes it impossible for external scripts to detect that an error occurred via the exit code.
Dive Deeper
The issue occurs in TEXT output mode when handling
GeminiEventType.Errorevents in the non-interactive CLI flow:Root Cause:
In
nonInteractiveCli.ts, when aGeminiEventType.Errorevent is received, the code writes the error message to stderr but continues execution instead of throwing an error. This causes the process to complete normally with exit code 0.Solution:
After writing the error to stderr, throw an error to interrupt the flow. The error will be caught by the catch block and processed through
handleError, which will exit the process with a non-zero exit code.Changes:
nonInteractiveCli.tsto throw error after writing to stderr whenGeminiEventType.Erroris received in TEXT modeshould handle API errors in text mode and exit with error codeto verify the fixImpact:
Reviewer Test Plan
Manual Testing
Create a simple Python script to test the exit code behavior:
Unit Tests
All existing tests pass to ensure no regression:
npm test packages/cli/src/nonInteractiveCli.test.tsTesting Matrix
Linked issues / bugs
Fixes #1375