Skip to content

Improve error handling for GetEvents with currently unsupported COM servers.#934

Merged
junkmd merged 6 commits intoenthought:mainfrom
junkmd:explicit_get_events_error
Mar 8, 2026
Merged

Improve error handling for GetEvents with currently unsupported COM servers.#934
junkmd merged 6 commits intoenthought:mainfrom
junkmd:explicit_get_events_error

Conversation

@junkmd
Copy link
Collaborator

@junkmd junkmd commented Mar 8, 2026

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 lack DISPID for connection point-based events, which are currently unsupported by GetEvents.

Enhanced Error Handling

Explicit NotImplementedError for invalid interface GUIDs

Previously, when a COM server's IProvideClassInfo2 returned GUID_NULL for its default source interface (a known issue with some servers like htmlfile), the system would fail with an uninformative KeyError.
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, an assert was used to verify the presence of DISPIDs.
This has been replaced with a formal check that raises a NotImplementedError with a detailed message.
This improvement is crucial for debugging issues with custom event interfaces (like those in IMAPI2FS) that inherit from IDispatch but lack the DISPIDs required for dispatch-based event sinks.

Expanded test coverage for COM servers

New test cases using MSHTML (htmlfile) and IMAPI2FS (MsftFileSystemImage) have been introduced.
These tests verify the new error handling paths.

junkmd added 6 commits March 8, 2026 14:30
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`.
@junkmd junkmd added this to the 1.4.17 milestone Mar 8, 2026
@junkmd junkmd added the tests enhance or fix tests label Mar 8, 2026
@codecov
Copy link

codecov bot commented Mar 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.97%. Comparing base (5c416b8) to head (1f5983b).
⚠️ Report is 1 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@junkmd junkmd merged commit 80ed427 into enthought:main Mar 8, 2026
82 of 101 checks passed
@junkmd junkmd deleted the explicit_get_events_error branch March 8, 2026 06:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests enhance or fix tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant