Fix #122777: The keyframe_insert method throws python exceptions
Just for the `pyrna_struct_keyframe_insert()` function, reduce the reporting level of keyframe insertion failures from `RPT_ERROR` to `RPT_WARNING`. This prevents the conversion of these reports to a Python exception. `CombinedKeyingResult::generate_reports()` now accepts an option argument `report_level`, so that the caller is in control over the type of reports it generates. Previously only errors were converted to exceptions; warnings were implicitly cleared and never displayed. To avoid these 'keyframe insertion failure' reports from becoming invisible, the `pyrna_struct_keyframe_insert()` function now sends any warnings to stdout (unless there were errors, in which case the old error-to-exception behaviour is still there). Pull Request: https://projects.blender.org/blender/blender/pulls/122827
This commit is contained in:
@@ -415,16 +415,26 @@ PyObject *pyrna_struct_keyframe_insert(BPy_StructRNA *self, PyObject *args, PyOb
|
||||
eInsertKeyFlags(options));
|
||||
const int success_count = combined_result.get_count(SingleKeyingResult::SUCCESS);
|
||||
if (success_count == 0) {
|
||||
combined_result.generate_reports(&reports);
|
||||
/* Ideally this would use the GUI presentation of RPT_ERROR, as the resulting pop-up has more
|
||||
* vertical space than the single-line warning in the status bar. However, semantically these
|
||||
* may not be errors at all, as skipping the keying of certain properties due to the 'only
|
||||
* insert available' flag is not an error.
|
||||
*
|
||||
* Furthermore, using RPT_ERROR here would cause this function to raise a Python exception,
|
||||
* rather than returning a boolean. */
|
||||
combined_result.generate_reports(&reports, RPT_WARNING);
|
||||
}
|
||||
result = success_count != 0;
|
||||
}
|
||||
|
||||
MEM_freeN((void *)path_full);
|
||||
|
||||
if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) {
|
||||
if (BPy_reports_to_error(&reports, PyExc_RuntimeError, false) == -1) {
|
||||
BKE_reports_free(&reports);
|
||||
return nullptr;
|
||||
}
|
||||
BPy_reports_write_stdout(&reports, nullptr);
|
||||
BKE_reports_free(&reports);
|
||||
|
||||
if (result) {
|
||||
WM_event_add_notifier(C, NC_ANIMATION | ND_ANIMCHAN | NA_EDITED, nullptr);
|
||||
|
||||
Reference in New Issue
Block a user