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.
This commit is contained in:
2022-04-06 16:15:11 +10:00
parent e4f71e5ef3
commit 2d2baeaf04
7 changed files with 87 additions and 54 deletions

View File

@@ -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);
}