diff --git a/common/lib/dependabot/errors.rb b/common/lib/dependabot/errors.rb index 539de9c76d..7ad258490a 100644 --- a/common/lib/dependabot/errors.rb +++ b/common/lib/dependabot/errors.rb @@ -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 diff --git a/updater/lib/dependabot/updater/error_handler.rb b/updater/lib/dependabot/updater/error_handler.rb index 06b6bbec37..acf0cdfc11 100644 --- a/updater/lib/dependabot/updater/error_handler.rb +++ b/updater/lib/dependabot/updater/error_handler.rb @@ -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 @@ -193,17 +138,6 @@ 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, @@ -211,8 +145,9 @@ def error_details_for(error, dependency: nil, dependency_group: nil) # rubocop:d dependency: dependency, dependency_group: dependency_group ) - { "error-type": "unknown_error" } end + + { "error-type": "unknown_error" } end def log_unknown_error_with_backtrace(error)