Skip to content

Conversation

@PiotrKarczmarz
Copy link
Collaborator

Adds defensive try-catch blocks with error logging to three VS event handler methods in DocumentsSyncService to prevent unhandled exceptions from destabilizing Visual Studio.

VS extensibility callbacks must not throw exceptions. Unhandled exceptions in IVsRunningDocTableEvents can crash Visual Studio or disable the extension.

Test plan

N/A

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Summary

This PR adds error handling via try-catch blocks to three methods in the document synchronization service: OnBeforeDocumentWindowShow, Subscribe, and UnsubscribeOnClosed. It also fixes indentation in OnAfterAttributeChangeEx.

Critical Issues

The primary concern is state inconsistency caused by swallowing exceptions. When exceptions occur partway through operations, state tracking collections (isSubscribed, openNotificationSend) may indicate successful subscription while actual event handlers were never attached or only partially attached. This creates a disconnect between the service's internal state and reality, preventing retry attempts and potentially causing memory leaks.

Considerations

  • Consider whether returning VSConstants.S_OK after catching exceptions in OnBeforeDocumentWindowShow is appropriate, as it signals success to Visual Studio even when the operation failed.
  • These event handler subscription patterns might benefit from an all-or-nothing approach where either all subscriptions succeed or all are rolled back on failure.

View this review on Amp

@github-actions
Copy link

github-actions bot commented Nov 19, 2025

Test Results

27 tests  ±0   26 ✅ ±0   3m 56s ⏱️ - 5m 22s
 1 suites ±0    1 💤 ±0 
 1 files   ±0    0 ❌ ±0 

Results for commit ec01e94. ± Comparison against base commit 4cff006.

♻️ This comment has been updated with latest results.

@PiotrKarczmarz PiotrKarczmarz merged commit 4db9c71 into main Nov 26, 2025
4 of 5 checks passed
@PiotrKarczmarz PiotrKarczmarz deleted the piotr/document-sync-try-catch branch November 26, 2025 15:56
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