From b4b18724bd1b363e77fcd42a703f2645916835de Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 30 Dec 2025 23:18:46 +0100 Subject: [PATCH] dtoolutil: Improve error messages for iostream wrappers --- dtool/src/dtoolutil/iostream_ext.cxx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/dtool/src/dtoolutil/iostream_ext.cxx b/dtool/src/dtoolutil/iostream_ext.cxx index 459f95c229..08272da20f 100644 --- a/dtool/src/dtoolutil/iostream_ext.cxx +++ b/dtool/src/dtoolutil/iostream_ext.cxx @@ -134,8 +134,9 @@ readinto(PyObject *b) { Py_buffer view; if (PyObject_GetBuffer(b, &view, PyBUF_CONTIG) == -1) { - PyErr_SetString(PyExc_TypeError, - "write() requires a contiguous, read-write bytes-like object"); + PyErr_Format(PyExc_TypeError, + "readinto() requires a contiguous, read-write bytes-like object, not '%.100s'", + Py_TYPE(b)->tp_name); return 0; } @@ -260,7 +261,9 @@ write(PyObject *b) { Py_buffer view; if (PyObject_GetBuffer(b, &view, PyBUF_CONTIG_RO) == -1) { - PyErr_SetString(PyExc_TypeError, "write() requires a contiguous buffer"); + PyErr_Format(PyExc_TypeError, + "write() requires a bytes-like object, not '%.100s'", + Py_TYPE(b)->tp_name); return; }