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 <campbell@blender.org>2022-04-06 09:15:11 +0300
committerCampbell Barton <campbell@blender.org>2022-04-06 11:02:58 +0300
commit2d2baeaf04d481f284bc2f098fb6d7ee9268151f (patch)
treedee60d7075b6febe402323d5b12085bdff544630 /source/blender/python/intern/bpy_interface_run.c
parente4f71e5ef345070dc0b21df35a049184d3e46645 (diff)
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.
Diffstat (limited to 'source/blender/python/intern/bpy_interface_run.c')
-rw-r--r--source/blender/python/intern/bpy_interface_run.c26
1 files changed, 25 insertions, 1 deletions
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);
}