-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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
[C API] Enhance PyErr_WriteUnraisable() API to pass an error message #108082
Comments
I already started to work on this, but was not sure about API, so left it to your return. I initially was going to add simple function: void PyErr_FormatUnraisable(const char *format, ...); With special case But it now creates the void PyErr_FormatUnraisable(PyObject *obj, const char *format, ...); With Or we always set Or we can keep void PyErr_FormatUnraisable(const char *format, ...);
void PyErr_FormatUnraisableObject(PyObject *obj, const char *format, ...); |
I wrote PR #108863 to remove the private _PyErr_WriteUnraisableMsg() function from the public C API. |
Also document the behavior when called with NULL.
Also document the behavior when called with NULL.
…GH-111455) Also document the behavior when called with NULL. (cherry picked from commit bca3305) Co-authored-by: Serhiy Storchaka <[email protected]>
…1455) (GH-111507) Also document the behavior when called with NULL. (cherry picked from commit bca3305) Co-authored-by: Serhiy Storchaka <[email protected]>
Replace most of calls of _PyErr_WriteUnraisableMsg() and some calls of PyErr_WriteUnraisable(NULL) with PyErr_FormatUnraisable().
Replace most of calls of _PyErr_WriteUnraisableMsg() and some calls of PyErr_WriteUnraisable(NULL) with PyErr_FormatUnraisable(). Co-authored-by: Victor Stinner <[email protected]>
Few calls of
They can be replaced with |
Replace the remaining calls with PyErr_FormatUnraisable().
As the author of _PyErr_WriteUnraisableMsg(), I suggest to remove _PyErr_WriteUnraisableMsg() and replace all _PyErr_WriteUnraisableMsg() usage with PyErr_FormatUnraisable(). My intent for passing object to the hook was to delegate the formatting to give the hook the opportunity to catch exception on formatting the object, and maybe use tracemalloc to see where the object was allocated, etc. But I don't think that these features are really useful and we should just skip/remove object, and just pass an error message to the hook. |
I created #111643 for this. |
Replace the remaining calls with PyErr_FormatUnraisable().
…GH-111455) Also document the behavior when called with NULL.
Replace most of calls of _PyErr_WriteUnraisableMsg() and some calls of PyErr_WriteUnraisable(NULL) with PyErr_FormatUnraisable(). Co-authored-by: Victor Stinner <[email protected]>
Replace the remaining calls with PyErr_FormatUnraisable().
Now we can replace more |
…GH-111455) Also document the behavior when called with NULL.
Replace most of calls of _PyErr_WriteUnraisableMsg() and some calls of PyErr_WriteUnraisable(NULL) with PyErr_FormatUnraisable(). Co-authored-by: Victor Stinner <[email protected]>
Replace the remaining calls with PyErr_FormatUnraisable().
…GH-111455) Also document the behavior when called with NULL.
Replace most of calls of _PyErr_WriteUnraisableMsg() and some calls of PyErr_WriteUnraisable(NULL) with PyErr_FormatUnraisable(). Co-authored-by: Victor Stinner <[email protected]>
Replace the remaining calls with PyErr_FormatUnraisable().
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Proposal:
I added a private
_PyErr_WriteUnraisableMsg()
API but it cannot be used in third party code, nor in stdlib extensions which try to avoid private/internal functions (like sqlite3). Moreover,_PyErr_WriteUnraisableMsg()
API doesn't allow to fully customize the error message.The limitation of
_PyErr_WriteUnraisableMsg()
affected PR #106674 which has to add; consider using ...
in the error message which is not great.@serhiy-storchaka suggested to add an API which allows string formatting, similar to
PyErr_Format()
._PyErr_WriteUnraisableMsg()
was added in issue #81010.By the way, we should go through all calls to PyErr_WriteUnraisable() and add more context to more these logs easier to get for developers: give more context about what the issue is, how to fix it, where it occurred, etc.
Linked PRs
The text was updated successfully, but these errors were encountered: