# Bug OP-19965 - RecurringMeeting occurrence init crashes with 500 on a draft template

Project: OpenProject
Status: closed
URL: https://community.openproject.org/work_packages/OP-19965

## Open points

_No work packages_

## Details

| Attribute | Value |
| --- | --- |
| Date |  |
| Priority | Medium |
| Module | API, Modules and project features / Meetings |
| Target versions | 17.9.0 |
| Observed in versions |  |
| Sprint |  |
| Backlog bucket |  |
| Bug found in version (deprecated) |  |
| Found in mobile app version |  |
| Follow-up feedback e-mail |  |
| Requires doc change | No |
| Accessibility | No |
| Pull preview |  |
| List |  |
| Labels |  |

## People

| Attribute | Value |
| --- | --- |
| Assignee |  |
| Accountable |  |
| Product manager |  |
| Developers |  |
| Designer |  |
| Ordered by |  |
| Signed off by |  |
| Interest by |  |

## Planning

| Attribute | Value |
| --- | --- |
| Relevance |  |

## Costs

| Attribute | Value |
| --- | --- |
| Votes |  |
| Work |  |
| Labor costs |  |

## Description

### Before filing a report

Confirmed reproducible on the latest available patch release of the 17.7 minor line (17.7.1, the latest at the time of testing) via direct REST API calls against a real instance. Searched community.openproject.org for existing reports (by "RecurringMeeting init draft template", "occurrence init 500", "InitOccurrenceService", "draft_template_failure") — found no existing report covering this. A minimal, verified fix is proposed below, also submitted as a pull request: https://github.com/opf/openproject/pull/24772

### Steps to reproduce

1. Login as a user with permissions to create meetings in a project.
2. Create a recurring meeting (`POST /api/v3/recurring_meetings` with `title`, `frequency`, `startTime`, `_links.project`, etc.). Its template Meeting is automatically created in `state: "draft"` (this is the default for every newly created recurring meeting template -- not itself a bug).
3. Immediately, without any further action on the template, call `POST /api/v3/recurring_meetings/{id}/occurrences/{start_time}/init` to materialize the first occurrence.

### What is the buggy behavior?

The request returns **HTTP 500** with an opaque error:
```json
{"_type":"Error","errorIdentifier":"urn:openproject-org:api:v3:errors:InternalServerError","message":"An internal error has occurred. expected at least one error"}
```

Root cause: `modules/meeting/app/services/recurring_meetings/init_occurrence_service.rb`'s `draft_template_failure` returns a bare `ServiceResult.failure(message: ...)` with no `errors:` key:
```ruby
def draft_template_failure
  ServiceResult.failure(message: I18n.t("recurring_meeting.occurrence.error_template_draft"))
end
```
The calling route (`modules/meeting/lib/api/v3/recurring_meetings/occurrences_by_recurring_meeting_api.rb`) does `fail ::API::Errors::ErrorBase.create_and_merge_errors(call.errors)` on failure, which calls `MultipleErrors.create_if_many(errors)`. Since `call.errors` is empty (nothing was ever added to it), `create_if_many([])` hits its own guard clause: `raise ArgumentError, "expected at least one error" unless errors.any?`. That uncaught `ArgumentError` is what surfaces as the 500.

### What is the expected behavior?

The request should return a clean **HTTP 422** explaining that the recurring meeting's template is still in draft mode, so the caller knows to move the template out of draft (e.g. via `PATCH /api/v3/meetings/{template_id}` with `state: "open"`) before retrying -- the same way any other validation failure on this endpoint is reported.

### Logs

```
HTTP/1.1 500 Internal Server Error
content-type: application/hal+json; charset=utf-8
{"_type":"Error","errorIdentifier":"urn:openproject-org:api:v3:errors:InternalServerError","message":"An internal error has occurred. expected at least one error"}
```

### Screenshots and other files

None — this is a pure backend/API bug with no UI reproduction path tested; the REST API reproduction above is sufficient to demonstrate it independent of any client.

### Environment information

**OpenProject installation type**

* Docker All-in-one container (official `openproject/openproject` image: `17.7.1`)

**OpenProject version**

Reproduced on `17.7.1` (the latest release in the 17.7 line at the time of testing). Confirmed present unchanged in source on the `dev` branch (checked against the full source checkout).

**Browser**

Not applicable — reproduced via direct REST API calls, no browser involved.

**Operating System**

Not applicable — server-side bug, reproduced against a Linux-based Docker container; the client OS is irrelevant to the reproduction.

**Language**

Not applicable — no UI/browser interaction involved in the reproduction.
