Improve error handling for GetEvents with currently unsupported COM servers.#934
Merged
junkmd merged 6 commits intoenthought:mainfrom Mar 8, 2026
Merged
Conversation
Add a test to verify that calling `GetEvents` on an `htmlfile` object raises a `KeyError`. The `IProvideClassInfo2` for this object returns a null GUID for its default source interface. This test confirms that `comtypes` correctly fails when it cannot find this null interface in the registry.
…nterface`. When `IProvideClassInfo2` returns `GUID_NULL` as the outgoing interface IID, `FindOutgoingInterface` now raises a `NotImplementedError`. This addresses cases where some COM servers (like `htmlfile`) return a null GUID instead of the default source interface's GUID. A new test case `test_retrieved_outgoing_iid_is_guid_null` has been added to `test_eventinterface.py` to verify this behavior.
…tgoingInterface`. Adds a comment to `FindOutgoingInterface` to explain that some COM servers may return `GUID_NULL` from `IProvideClassInfo2.GetGUID` instead of a valid interface IID. This clarifies the subsequent error handling for this specific edge case.
Add `Test_IMAPI2FS` to `test_eventinterface.py` to verify that `GetEvents` raises an `AssertionError` when used with the `MsftFileSystemImage` object. The default event interface `DFileSystemImageEvents` is a custom `TKIND_INTERFACE` that inherits from `IDispatch`, but is neither a dual nor pure dispatch interface. Its v-table methods, as generated from type info, lack the `dispid` attributes that `GetEvents` requires. This test confirms the expected failure.
Replace `assert` in `CreateEventReceiver` with an explicit check for `dispid`, raising `NotImplementedError` with a message when DISPIDs are missing.
Rename `Test_IMAPI2FS.test` to `test_event_methods_lack_dispids` to better reflect the cause of the `NotImplementedError`.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #934 +/- ##
==========================================
+ Coverage 88.91% 88.97% +0.05%
==========================================
Files 139 139
Lines 13606 13633 +27
==========================================
+ Hits 12098 12130 +32
+ Misses 1508 1503 -5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR improves the robustness and clarity of the event handling system in
client.It specifically addresses edge cases where COM servers return invalid interface
GUIDs or define event interfaces that lackDISPIDfor connection point-based events, which are currently unsupported byGetEvents.Enhanced Error Handling
Explicit
NotImplementedErrorfor invalid interface GUIDsPreviously, when a COM server's
IProvideClassInfo2returnedGUID_NULLfor its default source interface (a known issue with some servers likehtmlfile), the system would fail with an uninformativeKeyError.This is now explicitly caught and raised as a
NotImplementedError, providing a clearer signal that the server is not providing the necessary information to establish an event connection.Replaced assertions with descriptive exceptions for missing DISPIDs
In
CreateEventReceiver, anassertwas used to verify the presence of DISPIDs.This has been replaced with a formal check that raises a
NotImplementedErrorwith a detailed message.This improvement is crucial for debugging issues with custom event interfaces (like those in
IMAPI2FS) that inherit fromIDispatchbut lack the DISPIDs required for dispatch-based event sinks.Expanded test coverage for COM servers
New test cases using
MSHTML(htmlfile) andIMAPI2FS(MsftFileSystemImage) have been introduced.These tests verify the new error handling paths.