Skip to content

Improve error message extraction when Git hooks fail - #282524

Open
Fábio André Ramos Rodrigues (fabio-andre-rodrigues) wants to merge 7 commits into
microsoft:mainfrom
fabio-andre-rodrigues:better_error_message_when_git_hook_fails
Open

Improve error message extraction when Git hooks fail#282524
Fábio André Ramos Rodrigues (fabio-andre-rodrigues) wants to merge 7 commits into
microsoft:mainfrom
fabio-andre-rodrigues:better_error_message_when_git_hook_fails

Conversation

@fabio-andre-rodrigues

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

Copilot AI review requested due to automatic review settings December 10, 2025 16:29
@vs-code-engineering

vs-code-engineering Bot commented Dec 10, 2025

Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

Ladislau Szomoru (@lszomoru)

Matched files:

  • extensions/git/src/commands.ts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves error message extraction in the Git extension's error handling to prevent displaying misleading success/informational messages when Git hooks fail. The enhancement adds intelligent filtering to prioritize actual failure indicators over generic output.

Key changes:

  • Implemented multi-stage filtering logic to identify actual error messages in Git hook failures
  • Added detection patterns for failure indicators ("Failed", "exit code", "hook id")
  • Added exclusion patterns for success/skip messages to prevent them from being displayed as errors

Comment thread extensions/git/src/commands.ts
Comment thread extensions/git/src/commands.ts
@fabio-andre-rodrigues

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree [company="OutSystems"]

@fabio-andre-rodrigues

Fábio André Ramos Rodrigues (fabio-andre-rodrigues) commented Dec 10, 2025

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree company="OutSystems"

Extracted regex patterns into constants: Created FAILURE_PATTERNS and SUCCESS_PATTERNS arrays at the top of the default case block to eliminate duplication and improve maintainability.
Used the constants throughout: All regex pattern checks now use these constants via .some(pattern => pattern.test(line)).
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