From 4e87c30927b69134bdfd4c9999c21965ed09662f Mon Sep 17 00:00:00 2001 From: Pavel Rojtberg Date: Sat, 10 Feb 2024 01:36:21 +0100 Subject: [PATCH] SWIG: use argument_fail for consistent type error reporting --- Components/Overlay/include/ImGui.i | 7 +++---- OgreMain/include/Ogre.i | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Components/Overlay/include/ImGui.i b/Components/Overlay/include/ImGui.i index 3090845e48a..f63e1430fc5 100644 --- a/Components/Overlay/include/ImGui.i +++ b/Components/Overlay/include/ImGui.i @@ -28,7 +28,7 @@ if(SWIG_IsOK(res)) $1 = ($ltype)(argp); else - SWIG_exception_fail(SWIG_TypeError, "Expected size_t"); + %argument_fail(SWIG_TypeError, "size_t", $symname, $argnum); } %typecheck(SWIG_TYPECHECK_POINTER) ImTextureID { $1 = true; // actual check in the typemap @@ -40,7 +40,7 @@ if (SWIG_IsOK(res)) { $1 = ($ltype)argp; } else { - SWIG_exception_fail(SWIG_TypeError, "Expected ImVec4"); + %argument_fail(SWIG_TypeError, "ImVec4", $symname, $argnum); } } @@ -61,8 +61,7 @@ PyBuffer_Release(&view); if(view.ndim != 1 || strcmp(view.format, "f") != 0) { - PyErr_SetString(PyExc_TypeError, "Expected a 1D array of floats"); - SWIG_fail; + %argument_fail(SWIG_TypeError, "array(f)", $symname, $argnum); } $1 = ($ltype)view.buf; diff --git a/OgreMain/include/Ogre.i b/OgreMain/include/Ogre.i index d69a2aa44b0..4355417c735 100644 --- a/OgreMain/include/Ogre.i +++ b/OgreMain/include/Ogre.i @@ -356,7 +356,7 @@ CS_VECTOR_OPS(4); $1 = &tmp; if (!SWIG_IsOK(res)) - SWIG_exception_fail(SWIG_TypeError, "Expected float (Ogre::Radian) or Ogre::Degree"); + %argument_fail(SWIG_TypeError, "float (Ogre::Radian) or Ogre::Degree", $symname, $argnum); } } // punch through overload resolution @@ -396,7 +396,7 @@ CS_VECTOR_OPS(4); PyObject *o = PySequence_GetItem($input, i); if (!PyNumber_Check(o)) { Py_XDECREF(o); - SWIG_exception_fail(SWIG_TypeError, "Sequence elements must be numbers"); + %argument_fail(SWIG_TypeError, "Sequence[float]", $symname, $argnum); } temp.ptr()[i] = (float)PyFloat_AsDouble(o); Py_DECREF(o);