Skip to content

Commit

Permalink
Reuse common error methods in dry-run script
Browse files Browse the repository at this point in the history
  • Loading branch information
deivid-rodriguez committed Nov 29, 2023
1 parent 7948091 commit 7fd4fc7
Showing 1 changed file with 15 additions and 89 deletions.
104 changes: 15 additions & 89 deletions bin/dry-run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -402,101 +402,26 @@ def fetch_files(fetcher)
end
end
rescue StandardError => e
error_details = handle_dependabot_error(error: e)
error_details = Dependabot.fetcher_error_details(e)
raise unless error_details

puts " => handled error whilst fetching dependencies: #{error_details.fetch(:"error-type")} " \
"#{error_details.fetch(:"error-detail")}"

[]
end

# rubocop:disable Metrics/MethodLength
def handle_dependabot_error(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::BranchNotFound
{
"error-type": "branch_not_found",
"error-detail": { "branch-name": error.branch_name }
}
when Dependabot::DirectoryNotFound
{
"error-type": "directory_not_found",
"error-detail": { "directory-name": error.directory_name }
}
when Dependabot::DependencyFileNotParseable
{
"error-type": "dependency_file_not_parseable",
"error-detail": {
message: error.message,
"file-path": error.file_path
}
}
when Dependabot::DependencyFileNotFound
{
"error-type": "dependency_file_not_found",
"error-detail": { "file-path": error.file_path }
}
when Dependabot::PathDependenciesNotReachable
{
"error-type": "path_dependencies_not_reachable",
"error-detail": { dependencies: error.dependencies }
}
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
}
}
else
raise
end
def parse_dependencies(parser)
cached_read("dependencies") { parser.parse }
rescue StandardError => e
error_details = Dependabot.parser_error_details(e)
raise unless error_details

puts " => handled error whilst parsing dependencies: #{error_details.fetch(:"error-type")} " \
"#{error_details.fetch(:"error-detail")}"

[]
end
# rubocop:enable Metrics/MethodLength

def log_conflicting_dependencies(conflicting_dependencies)
return unless conflicting_dependencies.any?
Expand Down Expand Up @@ -568,7 +493,7 @@ def log_conflicting_dependencies(conflicting_dependencies)
reject_external_code: $options[:reject_external_code]
)

dependencies = cached_read("dependencies") { parser.parse }
dependencies = parse_dependencies(parser)

if $options[:dependency_names].nil?
dependencies.select!(&:top_level?)
Expand Down Expand Up @@ -810,7 +735,8 @@ def security_fix?(dependency)
puts "--commit--\n#{msg.commit_message}\n--/commit--"
end
rescue StandardError => e
error_details = handle_dependabot_error(error: e)
error_details = Dependabot.updater_error_details(e)
raise unless error_details

puts " => handled error whilst updating #{dep.name}: #{error_details.fetch(:"error-type")} " \
"#{error_details.fetch(:"error-detail")}"
Expand Down

0 comments on commit 7fd4fc7

Please sign in to comment.