From 712c5075197884dadffb30744d060e4abd756637 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Fri, 26 Sep 2025 12:57:39 +0200 Subject: [PATCH] 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 --- source/blender/python/intern/bpy_library_load.cc | 2 +- source/blender/python/intern/bpy_library_write.cc | 2 +- source/blender/python/intern/bpy_rna.cc | 8 +++++--- source/blender/python/intern/bpy_rna_anim.cc | 8 ++++---- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/source/blender/python/intern/bpy_library_load.cc b/source/blender/python/intern/bpy_library_load.cc index c5041e43f64..810265bdbb1 100644 --- a/source/blender/python/intern/bpy_library_load.cc +++ b/source/blender/python/intern/bpy_library_load.cc @@ -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; diff --git a/source/blender/python/intern/bpy_library_write.cc b/source/blender/python/intern/bpy_library_write.cc index 4a142a29873..bbd23a5f814 100644 --- a/source/blender/python/intern/bpy_library_write.cc +++ b/source/blender/python/intern/bpy_library_write.cc @@ -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); diff --git a/source/blender/python/intern/bpy_rna.cc b/source/blender/python/intern/bpy_rna.cc index e00ae611d01..54086e7a336 100644 --- a/source/blender/python/intern/bpy_rna.cc +++ b/source/blender/python/intern/bpy_rna.cc @@ -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; diff --git a/source/blender/python/intern/bpy_rna_anim.cc b/source/blender/python/intern/bpy_rna_anim.cc index f6fa9db319a..b3f6d765d9a 100644 --- a/source/blender/python/intern/bpy_rna_anim.cc +++ b/source/blender/python/intern/bpy_rna_anim.cc @@ -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);