error when a python operator gave an incorrect return value was near useless, re...
authorCampbell Barton <ideasman42@gmail.com>
Thu, 25 Aug 2011 17:54:30 +0000 (17:54 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 25 Aug 2011 17:54:30 +0000 (17:54 +0000)
source/blender/python/intern/bpy_operator.c
source/blender/python/intern/bpy_rna.c

index 7310878f66145a6a1c1a8f57deb1f7eabd597cf0..742dce3012489ec8092dadd4b530318fe4bdbf44 100644 (file)
@@ -293,7 +293,7 @@ static PyObject *pyop_call(PyObject *UNUSED(self), PyObject *args)
         * function corrects bpy.data (internal Main pointer) */
        BPY_modules_update(C);
 
-       /* needed for when WM_OT_read_factory_settings us called fro within a script */
+       /* needed for when WM_OT_read_factory_settings us called from within a script */
        bpy_import_main_set(CTX_data_main(C));
 
        /* return operator_ret as a bpy enum */
index 17992fdae3118f0fe658d17d8a14c5b3e37802a4..a3ff4314002b81a6c11b12a2f1ad3b1170e14a0b 100644 (file)
@@ -6417,7 +6417,21 @@ static int bpy_class_call(bContext *C, PointerRNA *ptr, FunctionRNA *func, Param
                        err= -1;
                }
                else if(ret_len==1) {
-                       err= pyrna_py_to_prop(&funcptr, pret_single, retdata_single, ret, "calling class function:");
+                       err= pyrna_py_to_prop(&funcptr, pret_single, retdata_single, ret, "");
+
+                       /* when calling operator funcs only gives Function.result with
+                        * no line number since the func has finished calling on error,
+                        * re-raise the exception with more info since it would be slow to
+                        * create prefix on every call (when there are no errors) */
+                       if(err == -1 && PyErr_Occurred()) {
+                               PyObject *error_type, *error_value, *error_traceback;
+                               PyErr_Fetch(&error_type, &error_value, &error_traceback);
+
+                               PyErr_Format(error_type,
+                                            "expected class %.200s, function %.200s: incompatible return value%S",
+                                            RNA_struct_identifier(ptr->type), RNA_function_identifier(func),
+                                            error_value);
+                       }
                }
                else if (ret_len > 1) {