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

OSError msg should display symbolic error codes #56971

Closed
jwilk mannequin opened this issue Aug 16, 2011 · 6 comments
Closed

OSError msg should display symbolic error codes #56971

jwilk mannequin opened this issue Aug 16, 2011 · 6 comments
Labels
3.10 only security fixes type-feature A feature request or enhancement

Comments

@jwilk
Copy link
Mannequin

jwilk mannequin commented Aug 16, 2011

BPO 12762
Nosy @warsaw, @pitrou, @jwilk, @bitdancer, @ZackerySpytz
Superseder
  • bpo-2920: Patch to print symbolic value of errno in OSError.str()
  • 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:

    assignee = None
    closed_at = <Date 2021-03-22.16:35:26.392>
    created_at = <Date 2011-08-16.17:09:05.767>
    labels = ['type-feature', '3.10']
    title = 'OSError msg should display symbolic error codes'
    updated_at = <Date 2021-03-22.16:35:26.390>
    user = 'https://github.com/jwilk'

    bugs.python.org fields:

    activity = <Date 2021-03-22.16:35:26.390>
    actor = 'ZackerySpytz'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-03-22.16:35:26.392>
    closer = 'ZackerySpytz'
    components = []
    creation = <Date 2011-08-16.17:09:05.767>
    creator = 'jwilk'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 12762
    keywords = []
    message_count = 6.0
    messages = ['142207', '142208', '143178', '187282', '187288', '389330']
    nosy_count = 5.0
    nosy_names = ['barry', 'pitrou', 'jwilk', 'r.david.murray', 'ZackerySpytz']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '2920'
    type = 'enhancement'
    url = 'https://bugs.python.org/issue12762'
    versions = ['Python 3.10']

    @jwilk
    Copy link
    Mannequin Author

    jwilk mannequin commented Aug 16, 2011

    It is a surprisingly common error in 3rd party code to write something like this:

    try:
    eggs()
    except OSError, e:
    if e.errno == 17:
    ham()

    This is wrong, because according to POSIX[0], “only […] symbolic names should be used in programs, since the actual value of the error number is unspecified.”

    I was wondering why Python programmers keep writing such unportable code - e.g. I've never seen C code that would compare errno variable with a hardcoded integer. I came into conclution that the Python interpreter itself is (partially) to blame. Currently exception message generated from errno looks like this:

    "[Errno 2] No such file or directory: '/punt'"

    It would be better if the message was:

    "[ENOENT] No such file or directory: '/punt'"

    or, if the above is too hard to implement, even:

    "No such file or directory: '/punt'"

    @jwilk
    Copy link
    Mannequin Author

    jwilk mannequin commented Aug 16, 2011

    @warsaw
    Copy link
    Member

    warsaw commented Aug 29, 2011

    I tend to agree that the errno is much less useful than the symbolic name. The former is useful and will be available as an attribute, but the latter should be used in the str. The change will probably break scads of doctests, but is probably worth it. :)

    BTW, this came up in the PEP-3151 discussions, but I agree it's orthogonal to that PEP.

    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented Apr 18, 2013

    It doesn't bother me that Python programmers can write unportable code, what with consenting adults and all that. Further the implementation of PEP-3151 in 3.3 allows specific exceptions to be caught, e.g. FileNotFoundError. I can't see anybody allowing the exception number being changed to the symbolic string or even omitted completely, so I'd recommend this is closed unless there's an extremely good reason not to do so.

    @bitdancer
    Copy link
    Member

    The enum module that is likely to land in 3.4 will allow us to fix this. We can discuss whether we want to just display the name, or both the name and the value. Omitting it would indeed be bad, IMO.

    @bitdancer bitdancer added the type-feature A feature request or enhancement label Apr 18, 2013
    @iritkatriel iritkatriel added the 3.10 only security fixes label Mar 22, 2021
    @iritkatriel iritkatriel changed the title EnvironmentError_str contributes to unportable code OSError msg should display symbolic error codes Mar 22, 2021
    @ZackerySpytz
    Copy link
    Mannequin

    ZackerySpytz mannequin commented Mar 22, 2021

    This is a duplicate of bpo-2920 (which has a PR).

    @ZackerySpytz ZackerySpytz mannequin closed this as completed Mar 22, 2021
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.10 only security fixes type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants