Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix error handling
Replace PyErr_Format() with PyErr_SetString()
  • Loading branch information
vstinner committed Jun 11, 2024
commit 242e6cb583e384ca67cf417ade13ead6c6927032
2 changes: 1 addition & 1 deletion Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -2907,7 +2907,7 @@ PyUnicode_FromFormatV(const char *format, va_list vargs)
if (unicode_decode_utf8_writer(&writer, f, len,
_Py_ERROR_STRICT, "strict") < 0) {
PyObject *exc = PyErr_GetRaisedException();
PyErr_Format(PyExc_ValueError,
PyErr_SetString(PyExc_ValueError,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why raise ValueError explicitly? If you want a ValueError for compatibility, UnicodeDecode is a subclass of ValueError, so this is a backward compatible change. Other functions which take const char * do not raise ValueError explicitly.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The error message helps debugging such issue: it points directly to the format string.

"PyUnicode_FromFormatV() expects a valid UTF-8-encoded "
"format string, got an invalid UTF-8 string");
_PyErr_ChainExceptions1(exc);
Expand Down