Skip to content

Commit

Permalink
Fixes [weekly 1.3k] [docker] RestClient::ServerBrokeConnection and re…
Browse files Browse the repository at this point in the history
…lated errors (dependabot#11456)

* adds handlers for bad registry response
  • Loading branch information
sachin-sandhu authored Feb 3, 2025
1 parent 7fa076b commit d08754e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
33 changes: 33 additions & 0 deletions common/lib/dependabot/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require "sorbet-runtime"
require "dependabot/utils"

# rubocop:disable Metrics/ModuleLength
module Dependabot
extend T::Sig

Expand All @@ -21,6 +22,7 @@ module ErrorAttributes
end

# rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/CyclomaticComplexity
sig { params(error: StandardError).returns(T.nilable(T::Hash[Symbol, T.untyped])) }
def self.fetcher_error_details(error)
case error
Expand Down Expand Up @@ -90,6 +92,11 @@ def self.fetcher_error_details(error)
"error-type": "private_source_authentication_failure",
"error-detail": { source: error.source }
}
when Dependabot::PrivateSourceBadResponse
{
"error-type": "private_source_bad_response",
"error-detail": { source: error.source }
}
when Octokit::Unauthorized
{ "error-type": "octokit_unauthorized" }
when Octokit::ServerError
Expand All @@ -113,6 +120,7 @@ def self.fetcher_error_details(error)
}
end
end
# rubocop:enable Metrics/CyclomaticComplexity

sig { params(error: StandardError).returns(T.nilable(T::Hash[Symbol, T.untyped])) }
def self.parser_error_details(error)
Expand Down Expand Up @@ -167,6 +175,11 @@ def self.parser_error_details(error)
"error-type": "private_source_authentication_failure",
"error-detail": { source: error.source }
}
when Dependabot::PrivateSourceBadResponse
{
"error-type": "private_source_bad_response",
"error-detail": { source: error.source }
}
when Dependabot::GitDependenciesNotReachable
{
"error-type": "git_dependencies_not_reachable",
Expand Down Expand Up @@ -262,6 +275,11 @@ def self.updater_error_details(error)
"error-type": "private_source_authentication_failure",
"error-detail": { source: error.source }
}
when Dependabot::PrivateSourceBadResponse
{
"error-type": "private_source_bad_response",
"error-detail": { source: error.source }
}
when Dependabot::DependencyNotFound
{
"error-type": "dependency_not_found",
Expand Down Expand Up @@ -645,6 +663,20 @@ def initialize(source)
end
end

class PrivateSourceBadResponse < DependabotError
extend T::Sig

sig { returns(String) }
attr_reader :source

sig { params(source: T.nilable(String)).void }
def initialize(source)
@source = T.let(sanitize_source(T.must(source)), String)
msg = "Bad response error while accessing source: #{@source}"
super(msg)
end
end

class PrivateSourceTimedOut < DependabotError
extend T::Sig

Expand Down Expand Up @@ -846,3 +878,4 @@ def initialize(message = nil)
end
end
end
# rubocop:enable Metrics/ModuleLength
2 changes: 1 addition & 1 deletion docker/lib/dependabot/docker/update_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def fetch_digest_of(tag)
attempt ||= 1
attempt += 1
return if attempt > 3 && e.is_a?(DockerRegistry2::NotFound)
raise if attempt > 3
raise PrivateSourceBadResponse, registry_hostname if attempt > 3

retry
rescue DockerRegistry2::RegistryAuthenticationException,
Expand Down

0 comments on commit d08754e

Please sign in to comment.