diff options
author | Campbell Barton <ideasman42@gmail.com> | 2020-07-27 06:46:51 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2020-07-27 14:00:50 +0300 |
commit | 7beef1fd33b37f62d14a7de7150cfc7b0d88f159 (patch) | |
tree | 4e4d9894321539fdfee8675bd8f0a17b01175eb3 /source | |
parent | d7cb67454df75cf17882d7fa742ba40eec347105 (diff) |
PyAPI: simplify syntax error reports
The result of syntax errors read poorly in reports,
resulting in cryptic and unhelpful information.
Change PyC_ExceptionBuffer_Simple only to extract the initial text,
making syntax errors when entering invalid numeric expressions into
buttons easier to follow.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/python/generic/py_capi_utils.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/source/blender/python/generic/py_capi_utils.c b/source/blender/python/generic/py_capi_utils.c index f46588206ee..406dbdafe22 100644 --- a/source/blender/python/generic/py_capi_utils.c +++ b/source/blender/python/generic/py_capi_utils.c @@ -634,7 +634,7 @@ error_cleanup: PyObject *PyC_ExceptionBuffer_Simple(void) { - PyObject *string_io_buf; + PyObject *string_io_buf = NULL; PyObject *error_type, *error_value, *error_traceback; @@ -648,7 +648,19 @@ PyObject *PyC_ExceptionBuffer_Simple(void) return NULL; } - string_io_buf = PyObject_Str(error_value); + if (PyErr_GivenExceptionMatches(error_type, PyExc_SyntaxError)) { + /* Special exception for syntax errors, + * in these cases the full error is verbose and not very useful, + * just use the initial text so we know what the error is. */ + if (PyTuple_CheckExact(error_value) && PyTuple_GET_SIZE(error_value) >= 1) { + string_io_buf = PyObject_Str(PyTuple_GET_ITEM(error_value, 0)); + } + } + + if (string_io_buf == NULL) { + string_io_buf = PyObject_Str(error_value); + } + /* Python does this too */ if (UNLIKELY(string_io_buf == NULL)) { string_io_buf = PyUnicode_FromFormat("<unprintable %s object>", Py_TYPE(error_value)->tp_name); |