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

Improved exception handling when importing the module #596

Merged
merged 1 commit into from
May 10, 2023

Conversation

piglei
Copy link
Contributor

@piglei piglei commented May 10, 2023

The current expection handling is too vague, and in certain circumstances, the error message may confuse the user.

For example, if an error occurs while importing the "_mysql" module, the original error message is as follows:

  File "MySQLdb/__init__.py", line 18, in <module>
    from . import _mysql
ImportError: /lib64/libstdc++.so.6: cannot allocate memory in static TLS block

But on the user side, he can only see the exception message like this:

/MySQLdb/__init__.py", line 24, in <module>
    version_info, _mysql.version_info, _mysql.__file__
NameError: name '_mysql' is not defined

This PR fixes this issue by making the exception handling statements more precise.

@codecov
Copy link

codecov bot commented May 10, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.13 🎉

Comparison is base (1f4fb4d) 86.15% compared to head (5996fe2) 86.28%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #596      +/-   ##
==========================================
+ Coverage   86.15%   86.28%   +0.13%     
==========================================
  Files           6        6              
  Lines         549      547       -2     
==========================================
- Hits          473      472       -1     
+ Misses         76       75       -1     
Impacted Files Coverage Δ
MySQLdb/__init__.py 86.84% <100.00%> (+1.84%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@methane methane merged commit b7255d3 into PyMySQL:main May 10, 2023
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.

2 participants