Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve COM error message #422

Closed
wants to merge 3 commits into from

Conversation

CristiFati
Copy link
Contributor

An alternative to #405.

ComTypes can end up installed (directly or indirectly) on non Windows OSes.

Message ImportError: cannot import name 'COMError' from '_ctypes' (/usr/lib/python3.8/lib-dynload/_ctypes.cpython-38-x86_64-linux-gnu.so) can be a bit hard to understand for some users (especially if there's no C background).

This proposes to make it more clear.

Copy link
Collaborator

@junkmd junkmd left a comment

Choose a reason for hiding this comment

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

Thank you for your suggestion.

try:
from _ctypes import COMError
except ImportError as e:
e.msg = "\n".join((
Copy link
Collaborator

Choose a reason for hiding this comment

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

Rewriting the exception message attribute directly is not recommended because the original exception information will be lost.

Raising a new exception while preserving the original exception information is easy with Py3 because the from clause can be used.

try:
    from _ctypes import COMError
except ImportError as e:
    msg =raise ImportError(msg) from e

Rather than making an effort to achieve the same thing in Py2 for the master branch, it would be better to work on the drop_py2 plan(#392) as it is in progress.

Please change the base of this PR to drop_py2 and rebase the branch as if it was made from drop_py2 as well, or remake branch and re-submit PR.

@CristiFati CristiFati changed the base branch from master to drop_py2 December 25, 2022 15:46
@CristiFati
Copy link
Contributor Author

Closing, as being replaced by #423.

@CristiFati CristiFati closed this Dec 25, 2022
@CristiFati CristiFati deleted the cfati_dev02 branch December 26, 2022 13:21
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.

None yet

2 participants