Return legacy /promote errors instead of a server error

What does this MR do and why?

A legacy /promote that fails now returns an error instead of a 500.

IssuePromoteService raises PromoteError on failure. The exception escaped Issues::UpdateService, so a /promote note sent through REST or GraphQL answered with a 500.

handle_promotion now rescues PromoteError. The message is added to the returned issue after the update runs.

This MR has no flag. It turns a 500 into a normal validation error, so it only changes requests that were already failing.

Details The message is added last because validation clears earlier errors. It is added on the result, so a combined move or clone reports it on the new issue.

IssuePromoteService also joins array messages into a sentence. Before, it raised the inspect form of the array.

References

  • Part of the split of !260607 (merged).
  • No dependencies. Based on master.
  • Merge before !261247 (merged), which drops the "Promoted issue to an epic." message on failure. That path is only reachable once /promote returns errors.

How to set up and validate locally

The /promote quick action is offered when the issue can be promoted. The promote service also refuses an issue that already has a parent epic when the group lacks multi-level epics (subepics, Ultimate). On Premium (epics on, subepics off) the command is offered and then fails with "Promotion is not supported.". That is the case to reproduce.

Tested in a fresh GDK (development, no SaaS simulation, GITLAB_LICENSE_MODE=test).

  1. Make the instance Premium. Skip this if the GDK already has a Premium license. If GDK runs with GITLAB_SIMULATE_SAAS=1, the group also needs a Premium plan on its subscription.

  2. Check the license in the console.

    License.current.plan                       # => "premium"
    License.feature_available?(:epics)         # => true
    License.feature_available?(:subepics)      # => false
  3. Create the data in a rails console as root. The last two lines confirm that /promote is offered and that the issue has a parent.

    root = User.find_by_username('root')
    org = Organizations::Organization.first
    Groups::CreateService.new(root, name: 'promote-repro', path: 'promote-repro', organization_id: org.id).execute
    group = Group.find_by_path('promote-repro')
    project = Projects::CreateService.new(root, name: 'proj', path: 'proj', namespace_id: group.id, organization_id: group.organization_id).execute
    epic = WorkItems::LegacyEpics::CreateService.new(group: group, current_user: root, params: { title: 'Parent epic' }).execute
    issue = Issues::CreateService.new(container: project, current_user: root, params: { title: 'Child issue', epic: epic }, perform_spam_check: false).execute[:issue]
    issue.can_be_promoted_to_epic?(root)      # => true, so /promote is offered
    WorkItem.find(issue.id).work_item_parent  # => the epic's work item
  4. Create a personal access token with the api scope for root. Any method works.

  5. Post the quick action as a REST note.

    curl --request POST --header "PRIVATE-TOKEN: <token>" \
      --data-urlencode "body=/promote" \
      "<gdk_url>/api/v4/projects/<project_id>/issues/<issue_iid>/notes"
    • master: HTTP 500 with {"message":"500 Internal Server Error"}. log/exceptions_json.log has WorkItems::LegacyEpics::IssuePromoteService::PromoteError with "Promotion is not supported.".
    • This branch: HTTP 400 with {"message":"400 Bad request - Note {:validation=>[\"Promotion is not supported.\"]}"}. There is no new PromoteError in exceptions_json.log. The issue stays open and not promoted, and its parent is unchanged.
  6. Optional, GraphQL on this branch.

    mutation {
      createNote(input: { noteableId: "gid://gitlab/Issue/<id>", body: "/promote" }) {
        errors
        quickActionsStatus { messages errorMessages }
      }
    }

    Expect HTTP 200, errors: ["Validation Promotion is not supported."] and quickActionsStatus.errorMessages: ["Promotion is not supported."]. quickActionsStatus.messages still says "Promoted issue to an epic.". That message is built before the service runs and is handled separately in !261247 (merged).

Specs:

  • ee/spec/services/ee/issues/update_service_spec.rb
  • ee/spec/services/work_items/legacy_epics/issue_promote_service_spec.rb
  • ee/spec/requests/api/notes_spec.rb

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist.

Generated with Claude Code

Edited by Alexandru Croitor

Merge request reports

Loading
Loading