From 26dbb4003ed4e6879955005eed50976dccd8a2fa Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Fri, 13 May 2022 23:20:58 +0200 Subject: [PATCH] Better error messages on missing module imports in Python modules --- src/pya/pya/pyaConvert.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/pya/pya/pyaConvert.cc b/src/pya/pya/pyaConvert.cc index e7f536bcd..09fccb5e7 100644 --- a/src/pya/pya/pyaConvert.cc +++ b/src/pya/pya/pyaConvert.cc @@ -455,7 +455,9 @@ object_to_python (void *obj, PYAObjectBase *self, const gsi::ClassBase *cls, boo // of the exposed property. Hence copying is safer. PyTypeObject *type = PythonModule::type_for_cls (clsact); - tl_assert (type != NULL); + if (!type) { + throw tl::Exception (tl::sprintf (tl::to_string (tr ("Requested type %s.%s is not bound to a Python class (did you load the '%s' module?)")), clsact->module (), clsact->name (), clsact->module ())); + } // create a instance and copy the value PyObject *new_pyobject = type->tp_alloc (type, 0); @@ -477,7 +479,9 @@ object_to_python (void *obj, PYAObjectBase *self, const gsi::ClassBase *cls, boo } else { PyTypeObject *type = PythonModule::type_for_cls (clsact); - tl_assert (type != NULL); + if (!type) { + throw tl::Exception (tl::sprintf (tl::to_string (tr ("Requested type %s.%s is not bound to a Python class (did you load the '%s' module?)")), clsact->module (), clsact->name (), clsact->module ())); + } // create a instance and copy the value PyObject *new_pyobject = type->tp_alloc (type, 0);