vscode
vscode copied to clipboard
Improve error message extraction when Git hooks fail
Summary
This PR improves the error message handling in the Git extension to better extract and display meaningful error messages when Git hooks fail. Previously, the code would simply take the first line of the error output, which could result in showing informational or success messages as errors.
Address Bug Report
Changes
- Enhanced error message extraction logic to prioritize actual error messages over informational messages
- Added intelligent filtering to identify lines indicating failures (e.g., "Failed", "exit code", "hook id")
- Added filtering to exclude success/skip messages (e.g., "Passed", "Skipped", "no files to check")
- Falls back to a generic "Git error" message when only success-related messages are found, preventing misleading error displays
Technical Details
The changes are in the CommandCenter class's error handling switch statement. The new logic:
- First looks for lines explicitly indicating failures (containing "Failed", "exit code", or "hook id:")
- If no explicit failure is found, looks for lines that don't indicate success/skip
- Only uses the first line if it's not a success-related message
- Falls back to a generic error message if only success messages are present
Testing
- Verify that actual hook failures show meaningful error messages
- Verify that success messages are not displayed as errors
- Verify that informational messages are filtered appropriately