From 2d2baeaf04d481f284bc2f098fb6d7ee9268151f Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 6 Apr 2022 16:15:11 +1000 Subject: Fix: T78228 Send all python errors to info editor Python exceptions are now shown in the info editor, this also resolves an old bug where errors were printed twice. This was originally based on D9752 by @ShadowChaser although many changes have been made from the original patch. Details: - BPy_errors_to_report no longer prints additional output. - BKE_report_print_test was added so it's possible to check if calling BKE_report also printed to the stdout. - Callers to BPy_errors_to_report are responsible for ensuring output is printed to the stdout/stderr. - Python exceptions no longer add a trailing newline, needed to avoid blank-space when displayed in the info-editor. --- source/blender/python/intern/bpy_interface_run.c | 26 +++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'source/blender/python/intern/bpy_interface_run.c') diff --git a/source/blender/python/intern/bpy_interface_run.c b/source/blender/python/intern/bpy_interface_run.c index 147c6cf8187..50a2722c276 100644 --- a/source/blender/python/intern/bpy_interface_run.c +++ b/source/blender/python/intern/bpy_interface_run.c @@ -271,7 +271,23 @@ static bool bpy_run_string_impl(bContext *C, if (retval == NULL) { ok = false; - BPy_errors_to_report(CTX_wm_reports(C)); + + ReportList reports; + BKE_reports_init(&reports, RPT_STORE); + BPy_errors_to_report(&reports); + + /* Ensure the reports are printed. */ + if (!BKE_reports_print_test(&reports, RPT_ERROR)) { + BKE_reports_print(&reports, RPT_ERROR); + } + + ReportList *wm_reports = CTX_wm_reports(C); + if (wm_reports) { + BLI_movelisttolist(&wm_reports->list, &reports.list); + } + else { + BKE_reports_clear(&reports); + } } else { Py_DECREF(retval); @@ -330,6 +346,14 @@ static void run_string_handle_error(struct BPy_RunErrInfo *err_info) } } + /* Print the reports if they were not printed already. */ + if ((err_info->reports == NULL) || !BKE_reports_print_test(err_info->reports, RPT_ERROR)) { + if (err_info->report_prefix) { + fprintf(stderr, "%s: ", err_info->report_prefix); + } + fprintf(stderr, "%s\n", err_str); + } + if (err_info->r_string != NULL) { *err_info->r_string = BLI_strdup(err_str); } -- cgit v1.2.3