made argument conversion for much more verbose, wasnt giving enough info with bad...
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Tue, 16 Mar 2010 17:19:42 +0000 (17:19 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Tue, 16 Mar 2010 17:19:42 +0000 (17:19 +0000)
(commit 27432 by Campbell from render25 branch)

source/blender/python/intern/bpy_rna.c
source/blender/python/intern/bpy_util.c

index 0c6709dff24238b6aaf274a57cc51c915464a976..b995fbb8800a99aaff2ed2ba7973bea750c1f3e8 100644 (file)
@@ -768,7 +768,7 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, ParameterList *parms, v
                } else /* continue... */
 #endif
                if (!PySequence_Check(value)) {
-                       PyErr_Format(PyExc_TypeError, "%.200s RNA array assignment expected a sequence instead of %.200s instance.", error_prefix, Py_TYPE(value)->tp_name);
+                       PyErr_Format(PyExc_TypeError, "%.200s RNA array assignment to %.200s.%.200s expected a sequence instead of %.200s instance.", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), Py_TYPE(value)->tp_name);
                        return -1;
                }
                /* done getting the length */
@@ -796,7 +796,7 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, ParameterList *parms, v
                                param = PyLong_AsSsize_t( value );
                        
                        if( param < 0 || param > 1) {
-                               PyErr_Format(PyExc_TypeError, "%.200s expected True/False or 0/1", error_prefix);
+                               PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected True/False or 0/1", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop));
                                return -1;
                        } else {
                                if(data)        *((int*)data)= param;
@@ -808,7 +808,7 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, ParameterList *parms, v
                {
                        int param = PyLong_AsSsize_t(value);
                        if (param==-1 && PyErr_Occurred()) {
-                               PyErr_Format(PyExc_TypeError, "%.200s expected an int type", error_prefix);
+                               PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected an int type", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop));
                                return -1;
                        } else {
                                RNA_property_int_clamp(ptr, prop, &param);
@@ -821,7 +821,7 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, ParameterList *parms, v
                {
                        float param = PyFloat_AsDouble(value);
                        if (PyErr_Occurred()) {
-                               PyErr_Format(PyExc_TypeError, "%.200s expected a float type", error_prefix);
+                               PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected a float type", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop));
                                return -1;
                        } else {
                                RNA_property_float_clamp(ptr, prop, (float *)&param);
@@ -835,7 +835,7 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, ParameterList *parms, v
                        char *param = _PyUnicode_AsString(value);
                        
                        if (param==NULL) {
-                               PyErr_Format(PyExc_TypeError, "%.200s expected a string type", error_prefix);
+                               PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected a string type", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop));
                                return -1;
                        } else {
                                if(data)        *((char**)data)= param;
@@ -864,7 +864,7 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, ParameterList *parms, v
                        }
                        else {
                                char *enum_str= pyrna_enum_as_string(ptr, prop);
-                               PyErr_Format(PyExc_TypeError, "%.200s expected a string enum or a set of strings in (%.200s)", error_prefix, enum_str);
+                               PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected a string enum or a set of strings in (%.2000s)", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), enum_str);
                                MEM_freeN(enum_str);
                                return -1;
                        }
@@ -886,13 +886,13 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, ParameterList *parms, v
                        }
 
                        if(!BPy_StructRNA_Check(value) && value != Py_None) {
-                               PyErr_Format(PyExc_TypeError, "%.200s expected a %.200s type", error_prefix, RNA_struct_identifier(ptype));
+                               PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected a %.200s type", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), RNA_struct_identifier(ptype));
                                return -1;
                        } else if((flag & PROP_NEVER_NULL) && value == Py_None) {
-                               PyErr_Format(PyExc_TypeError, "%.200s does not support a 'None' assignment %.200s type", error_prefix, RNA_struct_identifier(ptype));
+                               PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s does not support a 'None' assignment %.200s type", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), RNA_struct_identifier(ptype));
                                return -1;
                        } else if(value != Py_None && ((flag & PROP_ID_SELF_CHECK) && ptr->id.data == ((BPy_StructRNA*)value)->ptr.id.data)) {
-                               PyErr_Format(PyExc_TypeError, "%.200s ID type does not support assignment to its self", error_prefix);
+                               PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s ID type does not support assignment to its self", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop));
                                return -1;
                        } else {
                                BPy_StructRNA *param= (BPy_StructRNA*)value;
@@ -928,7 +928,7 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, ParameterList *parms, v
                                        else {
                                                PointerRNA tmp;
                                                RNA_pointer_create(NULL, ptype, NULL, &tmp);
-                                               PyErr_Format(PyExc_TypeError, "%.200s expected a %.200s type", error_prefix, RNA_struct_identifier(tmp.type));
+                                               PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected a %.200s type", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), RNA_struct_identifier(tmp.type));
                                                return -1;
                                        }
                                }
@@ -936,7 +936,7 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, ParameterList *parms, v
                                if(raise_error) {
                                        PointerRNA tmp;
                                        RNA_pointer_create(NULL, ptype, NULL, &tmp);
-                                       PyErr_Format(PyExc_TypeError, "%.200s expected a %.200s type", error_prefix, RNA_struct_identifier(tmp.type));
+                                       PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected a %.200s type", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), RNA_struct_identifier(tmp.type));
                                        return -1;
                                }
                        }
@@ -954,15 +954,22 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, ParameterList *parms, v
                        
                        /* convert a sequence of dict's into a collection */
                        if(!PySequence_Check(value)) {
-                               PyErr_Format(PyExc_TypeError, "%.200s expected a sequence of dicts for an RNA collection", error_prefix);
+                               PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected a sequence for an RNA collection, found a '%.200s' instead", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), Py_TYPE(value)->tp_name);
                                return -1;
                        }
-                       
+
                        seq_len = PySequence_Length(value);
                        for(i=0; i<seq_len; i++) {
                                item= PySequence_GetItem(value, i);
-                               if(item==NULL || PyDict_Check(item)==0) {
-                                       PyErr_Format(PyExc_TypeError, "%.200s expected a sequence of dicts for an RNA collection", error_prefix);
+
+                               if(item==NULL) {
+                                       PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s failed to get sequence index '%d' for an RNA collection", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), i);
+                                       Py_XDECREF(item);
+                                       return -1;
+                               }
+
+                               if(PyDict_Check(item)==0) {
+                                       PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected a each sequence member to be a dict for an RNA collection, found a '%.200s' instead", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), Py_TYPE(item)->tp_name);
                                        Py_XDECREF(item);
                                        return -1;
                                }
@@ -976,7 +983,13 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, ParameterList *parms, v
                                        RNA_property_collection_add(ptr, prop, &itemptr);
 
                                if(pyrna_pydict_to_props(&itemptr, item, 1, "Converting a python list to an RNA collection")==-1) {
+                                       PyObject *msg= BPY_exception_buffer();
+                                       char *msg_char= _PyUnicode_AsString(msg);
+
+                                       PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s error converting a member of a collection from a dicts into an RNA collection, failed with: %s", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), msg_char);
+
                                        Py_DECREF(item);
+                                       Py_DECREF(msg);
                                        return -1;
                                }
                                Py_DECREF(item);
@@ -985,7 +998,7 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, ParameterList *parms, v
                        break;
                }
                default:
-                       PyErr_Format(PyExc_AttributeError, "%.200s unknown property type (pyrna_py_to_prop)", error_prefix);
+                       PyErr_Format(PyExc_AttributeError, "%.200s %.200s.%.200s unknown property type (pyrna_py_to_prop)", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop));
                        return -1;
                        break;
                }
index a2bcfa63c31bf0b4af18c2e8969c083935532078..38462d1b1760df8e3186500e2b4100480ba6ff21 100644 (file)
@@ -243,8 +243,8 @@ PyObject *BPY_exception_buffer(void)
        
        PyErr_Clear();
        
-       /* import StringIO / io
-        * string_io = StringIO.StringIO()
+       /* import io
+        * string_io = io.StringIO()
         */
        
        if(! (string_io_mod= PyImport_ImportModule("io")) ) {