vscode icon indicating copy to clipboard operation
vscode copied to clipboard

Improve error message extraction when Git hooks fail

Open fabio-andre-rodrigues opened this issue 2 weeks ago • 3 comments

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

282523

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:

  1. First looks for lines explicitly indicating failures (containing "Failed", "exit code", or "hook id:")
  2. If no explicit failure is found, looks for lines that don't indicate success/skip
  3. Only uses the first line if it's not a success-related message
  4. 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

fabio-andre-rodrigues avatar Dec 10 '25 16:12 fabio-andre-rodrigues