Skip to content

gh-47169: Use the symbolic errno name in OSError error messages#14988

Open
ZackerySpytz wants to merge 4 commits into
python:mainfrom
ZackerySpytz:bpo-2920-OSError-errno-str
Open

gh-47169: Use the symbolic errno name in OSError error messages#14988
ZackerySpytz wants to merge 4 commits into
python:mainfrom
ZackerySpytz:bpo-2920-OSError-errno-str

Conversation

@ZackerySpytz
Copy link
Copy Markdown
Contributor

@ZackerySpytz ZackerySpytz commented Jul 28, 2019

For example:

>>> open('')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
FileNotFoundError: [Errno ENOENT] No such file or directory: ''

ENOENT is shown instead of the integer value.

https://bugs.python.org/issue2920

Comment thread Lib/test/test_exceptions.py Outdated
Copy link
Copy Markdown
Contributor

@gnprice gnprice left a comment

Choose a reason for hiding this comment

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

Thanks -- this will be a useful feature!

The patch calls PyImport_ImportModule("errno"), the equivalent of import errno, to get the table of names. In that bpo discussion, several people were concerned about doing an import here. It'd be good to say a few words about how this patch addresses those concerns.

Comment thread Objects/exceptions.c Outdated
Comment thread Objects/exceptions.c Outdated
@gnprice
Copy link
Copy Markdown
Contributor

gnprice commented Aug 8, 2019

Hmm, GitHub's UI now hides this comment above, so I'll make it again here in the main thread:

            if (errnomod == NULL) {
                PyErr_Clear();
                goto formaterrno;

I think this logic would be clearer by avoiding goto.

Probably a good way to do that is to pull this whole block into its own function.

(In discussion, I added:)

There's one very useful way of using goto in C which is done widely in the codebase: namely, to clean something up or tie up a loose end just before returning from a function. It serves much like a substitute for finally:.

Other cases where goto is worth it are quite rare, and I don't think this is one of them.


@ZackerySpytz , I see your comment suggesting you'd like to hear from a core developer on this question; wanted to pull this out just so the thread isn't lost in the GitHub mists. 😉

MaxwellDupre

This comment was marked as outdated.

@erlend-aasland erlend-aasland changed the title bpo-2920: Use the symbolic errno name in OSError error messages gh-47169: Use the symbolic errno name in OSError error messages Jan 5, 2024
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 7, 2026

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review stale Stale PR or inactive for long period of time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants