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>2009-06-13 17:57:56 +0400
committerCampbell Barton <ideasman42@gmail.com>2009-06-13 17:57:56 +0400
commitb592b6e8be051d590a6fa1806d44809c75df6515 (patch)
treeb8a19578a75a9204d5047a9c46bb4b9ad23e2475 /source/blender/python
parentd7e06a6d91dc2773bb8c4d0b6a0d8e71c775e02c (diff)
convert non-string pyoperator exceptions into strings if they are not already.
Diffstat (limited to 'source/blender/python')
-rw-r--r--source/blender/python/intern/bpy_operator_wrap.c37
1 files changed, 36 insertions, 1 deletions
diff --git a/source/blender/python/intern/bpy_operator_wrap.c b/source/blender/python/intern/bpy_operator_wrap.c
index 6ab990acdf5..8cd1bc64f11 100644
--- a/source/blender/python/intern/bpy_operator_wrap.c
+++ b/source/blender/python/intern/bpy_operator_wrap.c
@@ -140,12 +140,47 @@ static PyObject *pyop_dict_from_event(wmEvent *event)
/* TODO - a whole traceback would be ideal */
static void pyop_error_report(ReportList *reports)
{
+ const char *string;
PyObject *exception, *v, *tb;
PyErr_Fetch(&exception, &v, &tb);
if (exception == NULL)
return;
+
+ /* get the string from the exception */
+ if(v==NULL) {
+ string= "py exception not set";
+ }
+ else if(string = _PyUnicode_AsString(v)) {
+ /* do nothing */
+ }
+ else { /* a valid PyObject but not a string, try get its string value */
+ PyObject *repr;
+
+ Py_INCREF(v); /* incase clearing the error below somehow frees this */
+ PyErr_Clear();
+
+ repr= PyObject_Repr(v);
+
+ if(repr==NULL) {
+ PyErr_Clear();
+ string= "py exception found but can't be converted";
+ }
+ else {
+ string = _PyUnicode_AsString(repr);
+ Py_DECREF(repr);
+
+ if(string==NULL) { /* unlikely to happen */
+ PyErr_Clear();
+ string= "py exception found but can't be converted";
+ }
+ }
+
+ Py_DECREF(v); /* finished dealing with v, PyErr_Clear isnt called anymore so can decref it */
+ }
+ /* done getting the string */
+
/* Now we know v != NULL too */
- BKE_report(reports, RPT_ERROR, _PyUnicode_AsString(v));
+ BKE_report(reports, RPT_ERROR, string);
PyErr_Print();
}