Improve error reporting for Projects::DestroyService
Problem
A follow-up from the discussion: https://gitlab.com/gitlab-com/support/internal-requests/-/issues/22122#note_1699341845
In Projects::DestroyService we remove dependencies first and then call project.destroy!. However, if the dependency was not removed for some reason, then project.destroy! raises ActiveRecord::RecordNotDestroyed exception.
We display the exception error to the user, record it in Sentry and Kibana. But ActiveRecord::RecordNotDestroyed error message is very obscure: Failed to destroy Project with id=123.
Proposal
Provide a clear error message for ActiveRecord::RecordNotDestroyed case.
It was possible to extract the real error with a following code:
begin
project.destroy!
rescue ActiveRecord::RecordNotDestroyed => error
puts error.record.errors.full_messages
end