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
Misleading error from getspnam function of spwd module #62987
Comments
As root: $ sudo python3
[sudo] password for ethan:
Python 3.2.3 (default, Apr 10 2013, 05:07:54)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import spwd
>>> spwd.getspnam("I_don't_exist")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'getspnam(): name not found'
>>> spwd.getspnam("bin")
spwd.struct_spwd(sp_nam='bin', sp_pwd='*', sp_lstchg=15259, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1) As normal user: $ python3
Python 3.2.3 (default, Apr 10 2013, 05:07:54)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import spwd
>>> spwd.getspnam("I_don't_exist")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'getspnam(): name not found'
>>> spwd.getspnam("bin")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'getspnam(): name not found' People can be confused. How could the name not found if the name actually exists? Attached the patch to differentiate the error whether the error is really 'name not found' or 'permission denied'. I use the error message from the getspnam manual: There is another error message from getspnam beside EACCES (permission denied), which is ERANGE, but I don't think we need to handle this. |
PyErr_SetFromErrno(PyExc_OSError) looks more appropriate for permission denied error. However this change is backward incompatible so perhaps we have to left a KeyError. |
Attached the patch to accomodate Serhiy Storchaka's suggestion by using KeyError exception for backward compatibility. |
It was not a suggestion, it was a doubt. See also bpo-10388. |
Sorry about that. Okay, so for now, we wait for other people's suggestion, which way we should use to handle this situation? |
I think we should always raise OSError if errno is non-zero (and not KeyError). |
Sounds like we want something analogous to http://bugs.python.org/file33404/fix_error_message_getspall_v2.patch for this bug. Moving to patch needed. It looks like it would be easily tested too, so I'd like to see a test too please. |
Here is a patch with a test. |
As far as this change breaks compatibility. please add a note in the "Porting to Python 3.6" section in What's New. |
New changeset a1d738158390 by Berker Peksag in branch 'default': |
New changeset 430af393d8f1 by Victor Stinner in branch 'default': |
New changeset c1677c8f92e1 by Victor Stinner in branch 'default': |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: