PyAPI: include the property name & type in registration errors
This gives useful context in errors, also remove newline endings from exceptions.
This commit is contained in:
parent
9764d90fda
commit
d06b03f80d
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
PyObject *args_fake;
|
||||
/* 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;
|
||||
|
||||
if (*PyUnicode_AsUTF8(key) == '_') {
|
||||
PyObject *args_fake;
|
||||
const char *key_str = 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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue