Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2021-07-30 09:04:00 +0300
committerCampbell Barton <ideasman42@gmail.com>2021-07-30 09:04:00 +0300
commitd06b03f80da5ce7a5c833f25be783df3b4bc4c00 (patch)
tree41139f58f62f5252c1fcfb64a39505baa26e4e5b /source/blender/python
parent9764d90fda685492c8fcb3bb55a8949749d461f2 (diff)
PyAPI: include the property name & type in registration errors
This gives useful context in errors, also remove newline endings from exceptions.
Diffstat (limited to 'source/blender/python')
-rw-r--r--source/blender/python/intern/bpy_props.h5
-rw-r--r--source/blender/python/intern/bpy_rna.c27
2 files changed, 23 insertions, 9 deletions
diff --git a/source/blender/python/intern/bpy_props.h b/source/blender/python/intern/bpy_props.h
index bc7f0cfe416..e6bbd6f708d 100644
--- a/source/blender/python/intern/bpy_props.h
+++ b/source/blender/python/intern/bpy_props.h
@@ -33,7 +33,10 @@ StructRNA *pointer_type_from_py(PyObject *value, const char *error_prefix);
typedef struct {
PyObject_HEAD
- /* This isn't GC tracked, it's a function from `bpy.props` so it's not going away. */
+ /**
+ * Internally a #PyCFunctionObject type.
+ * \note This isn't GC tracked, it's a function from `bpy.props` so it's not going away.
+ */
void *fn;
PyObject *kw;
} BPy_PropDeferred;
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c
index 759630b73ac..dff96f74d62 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -8040,14 +8040,21 @@ static int deferred_register_prop(StructRNA *srna, PyObject *key, PyObject *item
PyObject *py_kw = ((BPy_PropDeferred *)item)->kw;
PyObject *py_srna_cobject, *py_ret;
+ /* Show the function name in errors to help give context. */
+ BLI_assert(PyCFunction_CheckExact(py_func));
+ PyMethodDef *py_func_method_def = ((PyCFunctionObject *)py_func)->m_ml;
+ const char *func_name = py_func_method_def->ml_name;
+
PyObject *args_fake;
+ const char *key_str = PyUnicode_AsUTF8(key);
- if (*PyUnicode_AsUTF8(key) == '_') {
+ if (*key_str == '_') {
PyErr_Format(PyExc_ValueError,
"bpy_struct \"%.200s\" registration error: "
- "%.200s could not register because the property starts with an '_'\n",
+ "'%.200s' %.200s could not register because it starts with an '_'",
RNA_struct_identifier(srna),
- PyUnicode_AsUTF8(key));
+ key_str,
+ func_name);
return -1;
}
py_srna_cobject = PyCapsule_New(srna, NULL, NULL);
@@ -8066,8 +8073,12 @@ static int deferred_register_prop(StructRNA *srna, PyObject *key, PyObject *item
*(PyCFunctionWithKeywords)PyCFunction_GET_FUNCTION(py_func) == BPy_CollectionProperty) &&
RNA_struct_idprops_contains_datablock(type_srna)) {
PyErr_Format(PyExc_ValueError,
- "bpy_struct \"%.200s\" doesn't support datablock properties\n",
- RNA_struct_identifier(srna));
+ "bpy_struct \"%.200s\" registration error: "
+ "'%.200s' %.200s could not register because "
+ "this type doesn't support data-block properties",
+ RNA_struct_identifier(srna),
+ key_str,
+ func_name);
return -1;
}
}
@@ -8085,12 +8096,12 @@ static int deferred_register_prop(StructRNA *srna, PyObject *key, PyObject *item
Py_DECREF(args_fake); /* Free's py_srna_cobject too. */
- // PyC_LineSpit();
PyErr_Format(PyExc_ValueError,
"bpy_struct \"%.200s\" registration error: "
- "%.200s could not register\n",
+ "'%.200s' %.200s could not register (see previous error)",
RNA_struct_identifier(srna),
- PyUnicode_AsUTF8(key));
+ key_str,
+ func_name);
return -1;
}