Title: `ctypes`: Make `COMError`, mentioned in the "Function prototypes" section of documentation, public. · Issue #126615 · python/cpython · GitHub
Open Graph Title: `ctypes`: Make `COMError`, mentioned in the "Function prototypes" section of documentation, public. · Issue #126615 · python/cpython
X Title: `ctypes`: Make `COMError`, mentioned in the "Function prototypes" section of documentation, public. · Issue #126615 · python/cpython
Description: Documentation I have been part of a project that handles COM with Python for several years now. When I first joined the project, _ctypes.COMError was a "mysterious error" to me. Over time, by implementing error handling within that proje...
Open Graph Description: Documentation I have been part of a project that handles COM with Python for several years now. When I first joined the project, _ctypes.COMError was a "mysterious error" to me. Over time, by imple...
X Description: Documentation I have been part of a project that handles COM with Python for several years now. When I first joined the project, _ctypes.COMError was a "mysterious error" to me. Over time...
Opengraph URL: https://github.com/python/cpython/issues/126615
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`ctypes`: Make `COMError`, mentioned in the \"Function prototypes\" section of documentation, public.","articleBody":"# Documentation\r\n\r\nI have been part of a project that handles COM with Python for several years now.\r\n\r\nWhen I first joined the project, `_ctypes.COMError` was a \"mysterious error\" to me. \r\n\r\nOver time, by implementing error handling within that project, contributing to [`comtypes`](https://github.com/enthought/comtypes/), and [adding `_ctypes.pyi` to typeshed](https://github.com/python/typeshed/pull/8582), I deepened my understanding of this error.\r\nYet, I always wondered why `ctypes` documentation never mentioned `COMError`.\r\n\r\nWhile reading through the function prototype section and working on gh-126384 and gh-126610, I realized that the section on \"extended error reporting\" may have implied `COMError`.\r\n\r\nhttps://github.com/python/cpython/blob/6293d00e7201f3f28b1f4512e57dc4f03855cabd/Doc/library/ctypes.rst?plain=1#L1793-L1800\r\n\r\n- If a foreign function generated from a function prototype without passing an `iid` fails to call a COM method, a [`WindowsError`](https://docs.python.org/3/library/exceptions.html#WindowsError) with the [`winerror` attribute](https://docs.python.org/3/library/exceptions.html#OSError.winerror) is raised.\r\n- On the other hand, if the foreign function is generated with an `iid` and fails to call, a `COMError` is raised, providing more \"extended error reporting\" with the following attributes:\r\n - `hresult`: an `HRESULT` value indicating an error, with any integer other than `S_OK` = `0`\r\n - `text`: an error message string\r\n - `details`: a tuple of length 5 representing `Description`, `Source`, `HelpFile`, `HelpContext`, and `scode`\r\n\r\nClearly mentioning this behavior would benefit not only those working with `comtypes` but also anyone involved in projects where `COMError` may arise.\r\nAt the very least, it would guide developers encountering this error to search `hresult` as a Windows error code.\r\n\r\nReferring to the `COMError` exception type as a private element such as `_CData` and specific to Windows such as `HRESULT` could help prevent developers from feeling it’s a \"mysterious error\" as I once did.\r\n\r\nAny opinions would be appreciated.\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-126686\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/junkmd","@type":"Person","name":"junkmd"},"datePublished":"2024-11-09T06:30:11.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/126615/cpython/issues/126615"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:333e2d8f-4a79-3140-99e0-8983d023f685 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A9EE:27BC0:69EBA0:9B7549:6A61F54D |
| html-safe-nonce | 916a7d0a8779b92b6072dbf651e070c79d9ded706bfd88f1cc3f3a01f8c75e0a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBOUVFOjI3QkMwOjY5RUJBMDo5Qjc1NDk6NkE2MUY1NEQiLCJ2aXNpdG9yX2lkIjoiNzg0MzE1NzkwOTc5MDkxMzg2OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 89a04741c850103486265867776ee90fbf155a6c12e4fcdc6c8416402b8db391 |
| hovercard-subject-tag | issue:2645693423 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/126615/issue_layout |
| twitter:image | https://opengraph.githubassets.com/076278ff19a1d6d0fc2954a1d274a1bbc32fd7c54320663d793ac777b6e4e724/python/cpython/issues/126615 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/076278ff19a1d6d0fc2954a1d274a1bbc32fd7c54320663d793ac777b6e4e724/python/cpython/issues/126615 |
| og:image:alt | Documentation I have been part of a project that handles COM with Python for several years now. When I first joined the project, _ctypes.COMError was a "mysterious error" to me. Over time, by imple... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | junkmd |
| hostname | github.com |
| expected-hostname | github.com |
| None | d88d9dd41cd32712dc23ff01ba406271c88c4858198430c255d591be42a1166f |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | a7f024eda6b8ce06d29c9276168423bfe05bafae |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width