Skip to content

Commit

Permalink
Extract updater error mapping to a method
Browse files Browse the repository at this point in the history
  • Loading branch information
deivid-rodriguez committed Nov 29, 2023
1 parent 8fc4f80 commit 7948091
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 71 deletions.
72 changes: 72 additions & 0 deletions common/lib/dependabot/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,78 @@ def self.parser_error_details(error)
{ "error-type": "server_error" }
end
end

def self.updater_error_details(error)
case error
when Dependabot::DependencyFileNotResolvable
{
"error-type": "dependency_file_not_resolvable",
"error-detail": { message: error.message }
}
when Dependabot::DependencyFileNotEvaluatable
{
"error-type": "dependency_file_not_evaluatable",
"error-detail": { message: error.message }
}
when Dependabot::GitDependenciesNotReachable
{
"error-type": "git_dependencies_not_reachable",
"error-detail": { "dependency-urls": error.dependency_urls }
}
when Dependabot::GitDependencyReferenceNotFound
{
"error-type": "git_dependency_reference_not_found",
"error-detail": { dependency: error.dependency }
}
when Dependabot::PrivateSourceAuthenticationFailure
{
"error-type": "private_source_authentication_failure",
"error-detail": { source: error.source }
}
when Dependabot::PrivateSourceTimedOut
{
"error-type": "private_source_timed_out",
"error-detail": { source: error.source }
}
when Dependabot::PrivateSourceCertificateFailure
{
"error-type": "private_source_certificate_failure",
"error-detail": { source: error.source }
}
when Dependabot::MissingEnvironmentVariable
{
"error-type": "missing_environment_variable",
"error-detail": {
"environment-variable": error.environment_variable
}
}
when Dependabot::GoModulePathMismatch
{
"error-type": "go_module_path_mismatch",
"error-detail": {
"declared-path": error.declared_path,
"discovered-path": error.discovered_path,
"go-mod": error.go_mod
}
}
when Dependabot::NotImplemented
{
"error-type": "not_implemented",
"error-detail": {
message: error.message
}
}
when *Octokit::RATE_LIMITED_ERRORS
# If we get a rate-limited error we let dependabot-api handle the
# retry by re-enqueing the update job after the reset
{
"error-type": "octokit_rate_limited",
"error-detail": {
"rate-limit-reset": error.response_headers["X-RateLimit-Reset"]
}
}
end
end
# rubocop:enable Metrics/MethodLength

class DependabotError < StandardError
Expand Down
77 changes: 6 additions & 71 deletions updater/lib/dependabot/updater/error_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,66 +124,11 @@ def log_job_error(error:, error_type:, error_detail: nil)
# For some specific errors, it also passes additional information to the
# exception service to aid in debugging, the optional arguments provide
# context to pass through in these cases.
def error_details_for(error, dependency: nil, dependency_group: nil) # rubocop:disable Metrics/MethodLength
def error_details_for(error, dependency: nil, dependency_group: nil)
error_details = Dependabot.updater_error_details(error)
return error_details if error_details

case error
when Dependabot::DependencyFileNotResolvable
{
"error-type": "dependency_file_not_resolvable",
"error-detail": { message: error.message }
}
when Dependabot::DependencyFileNotEvaluatable
{
"error-type": "dependency_file_not_evaluatable",
"error-detail": { message: error.message }
}
when Dependabot::GitDependenciesNotReachable
{
"error-type": "git_dependencies_not_reachable",
"error-detail": { "dependency-urls": error.dependency_urls }
}
when Dependabot::GitDependencyReferenceNotFound
{
"error-type": "git_dependency_reference_not_found",
"error-detail": { dependency: error.dependency }
}
when Dependabot::PrivateSourceAuthenticationFailure
{
"error-type": "private_source_authentication_failure",
"error-detail": { source: error.source }
}
when Dependabot::PrivateSourceTimedOut
{
"error-type": "private_source_timed_out",
"error-detail": { source: error.source }
}
when Dependabot::PrivateSourceCertificateFailure
{
"error-type": "private_source_certificate_failure",
"error-detail": { source: error.source }
}
when Dependabot::MissingEnvironmentVariable
{
"error-type": "missing_environment_variable",
"error-detail": {
"environment-variable": error.environment_variable
}
}
when Dependabot::GoModulePathMismatch
{
"error-type": "go_module_path_mismatch",
"error-detail": {
"declared-path": error.declared_path,
"discovered-path": error.discovered_path,
"go-mod": error.go_mod
}
}
when Dependabot::NotImplemented
{
"error-type": "not_implemented",
"error-detail": {
message: error.message
}
}
when Dependabot::SharedHelpers::HelperSubprocessFailed
# If a helper subprocess has failed the error may include sensitive
# info such as file contents or paths. This information is already
Expand All @@ -193,26 +138,16 @@ def error_details_for(error, dependency: nil, dependency_group: nil) # rubocop:d
sanitized_error = SubprocessFailed.new(msg, raven_context: error.raven_context)
sanitized_error.set_backtrace(error.backtrace)
service.capture_exception(error: sanitized_error, job: job)

{ "error-type": "unknown_error" }
when *Octokit::RATE_LIMITED_ERRORS
# If we get a rate-limited error we let dependabot-api handle the
# retry by re-enqueing the update job after the reset
{
"error-type": "octokit_rate_limited",
"error-detail": {
"rate-limit-reset": error.response_headers["X-RateLimit-Reset"]
}
}
else
service.capture_exception(
error: error,
job: job,
dependency: dependency,
dependency_group: dependency_group
)
{ "error-type": "unknown_error" }
end

{ "error-type": "unknown_error" }
end

def log_unknown_error_with_backtrace(error)
Expand Down

0 comments on commit 7948091

Please sign in to comment.