Skip to content

Return meaningful error when adding one child epic at time and it fails

This issue is about fixing the error message for a case only one epic is being added to the parent epic and creating this relation fails.

Summary

When adding an epic fails a general 404 error is returned. We should return a specific error instead, at least when a user tries to add only one child epic at time. The errors returned could be:

  • parrent epic == child epic
  • child epic is already in the structure
  • level would be too deep after adding a child epic
  • child epic doesn't belong to group (or subgroup) of a parent epic

https://gitlab.com/gitlab-org/gitlab/blob/master/ee/app/models/ee/epic.rb#L324 for more context

One of the examples:

Adding an Epic with depth < 4 as a sub-epic of another with levels of ancestry < 4 results in a 404 when total depth > 5.

Steps to reproduce

  1. Create 7 new Epics.
  2. Organise them into a hierarchy such that:
Epic 1
> Epic 2
>> Epic 3
>>> Epic 4

Epic 5
> Epic 6
>> Epic 7
  1. Attempt to add Epic 5 as a sub-epic of Epic 4

What is the current bug behavior?

Currently a 404 is returned with the error message No Epic found for given params.

What is the expected correct behavior?

A 409 should be returned with the message Epic hierarchy level too deep, as when Epics are added sequentially (i.e. epic already has depth 5 and you try to add another sub-epic).

This is important because it will affect the error message shown to the user when #32557 (closed) is complete.

Possible fixes

(If you can, link to the line of code that might be responsible for the problem)

Edited by Jarka Košanová