summaryrefslogtreecommitdiff
path: root/lib/gitlab/git
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-05-04 12:17:18 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2023-05-04 12:17:18 +0000
commitfb5d3cceb8d43f8c2dc22a5d8c74327e9397f2e8 (patch)
treedbd3a17217fa46cf279ed692b605e03222fca360 /lib/gitlab/git
parent6cd4578a23ffe0fb94632f83a07a25d01f8d6821 (diff)
downloadgitlab-ce-fb5d3cceb8d43f8c2dc22a5d8c74327e9397f2e8.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/git')
-rw-r--r--lib/gitlab/git/wraps_gitaly_errors.rb40
1 files changed, 33 insertions, 7 deletions
diff --git a/lib/gitlab/git/wraps_gitaly_errors.rb b/lib/gitlab/git/wraps_gitaly_errors.rb
index 1d34f3c8eb2..20bcf3585e1 100644
--- a/lib/gitlab/git/wraps_gitaly_errors.rb
+++ b/lib/gitlab/git/wraps_gitaly_errors.rb
@@ -5,14 +5,40 @@ module Gitlab
module WrapsGitalyErrors
def wrapped_gitaly_errors(&block)
yield block
- rescue GRPC::NotFound => e
- raise Gitlab::Git::Repository::NoRepository, e
- rescue GRPC::InvalidArgument => e
- raise ArgumentError, e
- rescue GRPC::DeadlineExceeded => e
- raise Gitlab::Git::CommandTimedOut, e
rescue GRPC::BadStatus => e
- raise Gitlab::Git::CommandError, e
+ # The GRPC::BadStatus is the fundamental error that serves as the basis for all other gRPC error categories,
+ # including GRPC::InvalidArgument. It is essential to note that rescuing the specific exception class does not
+ # account for all possible cases. In this regard, a status exception can be directly generated from
+ # GRPC::BadStatus. Therefore, it is recommended that we capture and rescue the GRPC::BadStatus and assert the
+ # status code to ensure adequate coverage of error cases.
+ case e.code
+ when GRPC::Core::StatusCodes::NOT_FOUND
+ raise Gitlab::Git::Repository::NoRepository, e
+ when GRPC::Core::StatusCodes::INVALID_ARGUMENT
+ raise ArgumentError, e
+ when GRPC::Core::StatusCodes::DEADLINE_EXCEEDED
+ raise Gitlab::Git::CommandTimedOut, e
+ when GRPC::Core::StatusCodes::RESOURCE_EXHAUSTED
+ handle_resource_exhausted(e)
+ else
+ raise Gitlab::Git::CommandError, e
+ end
+ end
+
+ private
+
+ def handle_resource_exhausted(exception)
+ detail = Gitlab::GitalyClient.decode_detailed_error(exception)
+
+ case detail.class.name
+ when Gitaly::LimitError.name
+ retry_after = detail&.retry_after&.seconds
+ raise ResourceExhaustedError.new(
+ "Upstream Gitaly has been exhausted: #{detail.error_message}. Try again later", retry_after
+ )
+ else
+ raise ResourceExhaustedError, _("Upstream Gitaly has been exhausted. Try again later")
+ end
end
end
end