UI: improve errors when evaluating a number button fails
Showing the Python error without any explanation is often
not enough information and doesn't hint that the error was in the
user input.
The error report from a invalid expression such as '..1' used to be:
('invalid syntax', ('<string>', 1, 1, '..1'))
Now reads:
Error evaluating number, see Info editor for details: invalid syntax
Address issue raised by T78913.
This commit is contained in:
@@ -617,8 +617,11 @@ void BPY_DECREF_RNA_INVALIDATE(void *pyob_ptr)
|
||||
/**
|
||||
* \return success
|
||||
*/
|
||||
bool BPY_execute_string_as_number(
|
||||
bContext *C, const char *imports[], const char *expr, const bool verbose, double *r_value)
|
||||
bool BPY_execute_string_as_number(bContext *C,
|
||||
const char *imports[],
|
||||
const char *expr,
|
||||
const char *report_prefix,
|
||||
double *r_value)
|
||||
{
|
||||
PyGILState_STATE gilstate;
|
||||
bool ok = true;
|
||||
@@ -637,8 +640,8 @@ bool BPY_execute_string_as_number(
|
||||
ok = PyC_RunString_AsNumber(imports, expr, "<expr as number>", r_value);
|
||||
|
||||
if (ok == false) {
|
||||
if (verbose) {
|
||||
BPy_errors_to_report_ex(CTX_wm_reports(C), false, false);
|
||||
if (report_prefix != NULL) {
|
||||
BPy_errors_to_report_ex(CTX_wm_reports(C), report_prefix, false, false);
|
||||
}
|
||||
else {
|
||||
PyErr_Clear();
|
||||
@@ -656,7 +659,7 @@ bool BPY_execute_string_as_number(
|
||||
bool BPY_execute_string_as_string_and_size(bContext *C,
|
||||
const char *imports[],
|
||||
const char *expr,
|
||||
const bool verbose,
|
||||
const char *report_prefix,
|
||||
char **r_value,
|
||||
size_t *r_value_size)
|
||||
{
|
||||
@@ -674,8 +677,8 @@ bool BPY_execute_string_as_string_and_size(bContext *C,
|
||||
ok = PyC_RunString_AsStringAndSize(imports, expr, "<expr as str>", r_value, r_value_size);
|
||||
|
||||
if (ok == false) {
|
||||
if (verbose) {
|
||||
BPy_errors_to_report_ex(CTX_wm_reports(C), false, false);
|
||||
if (report_prefix != NULL) {
|
||||
BPy_errors_to_report_ex(CTX_wm_reports(C), false, false, report_prefix);
|
||||
}
|
||||
else {
|
||||
PyErr_Clear();
|
||||
@@ -687,12 +690,15 @@ bool BPY_execute_string_as_string_and_size(bContext *C,
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool BPY_execute_string_as_string(
|
||||
bContext *C, const char *imports[], const char *expr, const bool verbose, char **r_value)
|
||||
bool BPY_execute_string_as_string(bContext *C,
|
||||
const char *imports[],
|
||||
const char *expr,
|
||||
const char *report_prefix,
|
||||
char **r_value)
|
||||
{
|
||||
size_t value_dummy_size;
|
||||
return BPY_execute_string_as_string_and_size(
|
||||
C, imports, expr, verbose, r_value, &value_dummy_size);
|
||||
C, imports, expr, report_prefix, r_value, &value_dummy_size);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -700,8 +706,11 @@ bool BPY_execute_string_as_string(
|
||||
*
|
||||
* \return success
|
||||
*/
|
||||
bool BPY_execute_string_as_intptr(
|
||||
bContext *C, const char *imports[], const char *expr, const bool verbose, intptr_t *r_value)
|
||||
bool BPY_execute_string_as_intptr(bContext *C,
|
||||
const char *imports[],
|
||||
const char *expr,
|
||||
const char *report_prefix,
|
||||
intptr_t *r_value)
|
||||
{
|
||||
BLI_assert(r_value && expr);
|
||||
PyGILState_STATE gilstate;
|
||||
@@ -717,8 +726,8 @@ bool BPY_execute_string_as_intptr(
|
||||
ok = PyC_RunString_AsIntPtr(imports, expr, "<expr as intptr>", r_value);
|
||||
|
||||
if (ok == false) {
|
||||
if (verbose) {
|
||||
BPy_errors_to_report_ex(CTX_wm_reports(C), false, false);
|
||||
if (report_prefix != NULL) {
|
||||
BPy_errors_to_report_ex(CTX_wm_reports(C), report_prefix, false, false);
|
||||
}
|
||||
else {
|
||||
PyErr_Clear();
|
||||
|
||||
Reference in New Issue
Block a user