diff --git a/modules/meeting/app/services/recurring_meetings/init_occurrence_service.rb b/modules/meeting/app/services/recurring_meetings/init_occurrence_service.rb index 4a376ae744af..13b090124158 100644 --- a/modules/meeting/app/services/recurring_meetings/init_occurrence_service.rb +++ b/modules/meeting/app/services/recurring_meetings/init_occurrence_service.rb @@ -62,7 +62,8 @@ def perform end def draft_template_failure - ServiceResult.failure(message: I18n.t("recurring_meeting.occurrence.error_template_draft")) + recurring_meeting.errors.add(:base, I18n.t("recurring_meeting.occurrence.error_template_draft")) + ServiceResult.failure(errors: recurring_meeting.errors) end def validate_contract diff --git a/modules/meeting/spec/services/recurring_meetings/init_occurrence_service_spec.rb b/modules/meeting/spec/services/recurring_meetings/init_occurrence_service_spec.rb index 5204596f612f..a44cda2daf02 100644 --- a/modules/meeting/spec/services/recurring_meetings/init_occurrence_service_spec.rb +++ b/modules/meeting/spec/services/recurring_meetings/init_occurrence_service_spec.rb @@ -67,6 +67,15 @@ expect(created_meeting).to be_nil end + it "carries a non-empty errors object usable by the API layer" do + # Regression test: draft_template_failure used to return only a + # message with no errors:, which crashed + # API::Errors::ErrorBase.create_and_merge_errors(call.errors) with an + # ArgumentError ("expected at least one error") when the API route + # tried to build a MultipleErrors response from an empty error list. + expect(service_result.errors).not_to be_empty + end + it "does not add an occurrence" do expect { instance.call(**params) } .not_to change { series.meetings.not_templated.count }