Logging: Do not print Python API errors that will throw an exception

Python API functions would both report an error through CLOG and throw an
exception. However this is a problem when --debug-exit-on-error is used,
as tests and other scripts will not have the opportunity to catch the exception
before Blender exits.

Now don't print such reports through CLOG. Note that these usages of
BKE_reports_init have their print level set to error, so were already not
printing info and warning reports (which is not something we generally
want Python API calls to do, they should be silent).

Ref #146256

Pull Request: https://projects.blender.org/blender/blender/pulls/146801
This commit is contained in:
Brecht Van Lommel
2025-09-26 12:57:39 +02:00
committed by Brecht Van Lommel
parent 8409f81f9f
commit 712c507519
4 changed files with 11 additions and 9 deletions

View File

@@ -472,7 +472,7 @@ static PyObject *bpy_lib_enter(BPy_Library *self)
ReportList *reports = &self->reports;
BlendFileReadReport *bf_reports = &self->bf_reports;
BKE_reports_init(reports, RPT_STORE);
BKE_reports_init(reports, RPT_STORE | RPT_PRINT_HANDLED_BY_OWNER);
memset(bf_reports, 0, sizeof(*bf_reports));
bf_reports->reports = reports;

View File

@@ -159,7 +159,7 @@ static PyObject *bpy_lib_write(BPy_PropertyRNA *self, PyObject *args, PyObject *
/* write blend */
ReportList reports;
BKE_reports_init(&reports, RPT_STORE);
BKE_reports_init(&reports, RPT_STORE | RPT_PRINT_HANDLED_BY_OWNER);
bool success = partial_write_ctx.write(
filepath_abs, write_flags, path_remap.value_found, reports);

View File

@@ -2053,7 +2053,7 @@ static int pyrna_py_to_prop(
/* Data == nullptr, assign to RNA. */
if ((param == nullptr) || RNA_struct_is_a(param->ptr->type, ptr_type)) {
ReportList reports;
BKE_reports_init(&reports, RPT_STORE);
BKE_reports_init(&reports, RPT_STORE | RPT_PRINT_HANDLED_BY_OWNER);
RNA_property_pointer_set(
ptr, prop, (param == nullptr) ? PointerRNA_NULL : *param->ptr, &reports);
const int err = BPy_reports_to_error(&reports, PyExc_RuntimeError, true);
@@ -6856,7 +6856,9 @@ static PyObject *pyrna_func_vectorcall(PyObject *callable,
ReportList reports;
bContext *C = BPY_context_get();
BKE_reports_init(&reports, RPT_STORE);
/* No need to print any reports. We will turn errors into Python exceptions, and
* Python API calls should be silent and not print info or warning messages. */
BKE_reports_init(&reports, RPT_STORE | RPT_PRINT_HANDLED_BY_OWNER);
RNA_function_call(C, &reports, self_ptr, self_func, &parms);
err = BPy_reports_to_error(&reports, PyExc_RuntimeError, true);
@@ -10116,7 +10118,7 @@ static PyObject *pyrna_register_class(PyObject * /*self*/, PyObject *py_class)
C = BPY_context_get();
/* Call the register callback with reports & identifier. */
BKE_reports_init(&reports, RPT_STORE);
BKE_reports_init(&reports, RPT_STORE | RPT_PRINT_HANDLED_BY_OWNER);
identifier = ((PyTypeObject *)py_class)->tp_name;

View File

@@ -358,7 +358,7 @@ PyObject *pyrna_struct_keyframe_insert(BPy_StructRNA *self, PyObject *args, PyOb
ReportList reports;
bool result = false;
BKE_reports_init(&reports, RPT_STORE);
BKE_reports_init(&reports, RPT_STORE | RPT_PRINT_HANDLED_BY_OWNER);
/* This assumes that keyframes are only added on original data & using the active depsgraph. If
* it turns out to be necessary for some reason to insert keyframes on evaluated objects, we can
@@ -497,7 +497,7 @@ PyObject *pyrna_struct_keyframe_delete(BPy_StructRNA *self, PyObject *args, PyOb
ReportList reports;
bool result = false;
BKE_reports_init(&reports, RPT_STORE);
BKE_reports_init(&reports, RPT_STORE | RPT_PRINT_HANDLED_BY_OWNER);
if (self->ptr->type == &RNA_NlaStrip) {
/* Handle special properties for NLA Strips, whose F-Curves are stored on the
@@ -605,7 +605,7 @@ PyObject *pyrna_struct_driver_add(BPy_StructRNA *self, PyObject *args)
ReportList reports;
int result;
BKE_reports_init(&reports, RPT_STORE);
BKE_reports_init(&reports, RPT_STORE | RPT_PRINT_HANDLED_BY_OWNER);
result = ANIM_add_driver(&reports,
self->ptr->owner_id,
@@ -686,7 +686,7 @@ PyObject *pyrna_struct_driver_remove(BPy_StructRNA *self, PyObject *args)
short result;
ReportList reports;
BKE_reports_init(&reports, RPT_STORE);
BKE_reports_init(&reports, RPT_STORE | RPT_PRINT_HANDLED_BY_OWNER);
result = ANIM_remove_driver(self->ptr->owner_id, path_full, index);