Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes part of [4.8k weekly] [go_modules] go_modules exceptions #11403

Merged
merged 1 commit into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ class GoModUpdater
/Out of diskspace/
].freeze, T::Array[Regexp])

GO_LANG = "Go"

AMBIGUOUS_ERROR_MESSAGE = /ambiguous import: found package (?<package>.*) in multiple modules/

GO_VERSION_MISMATCH = /requires go (?<current_ver>.*) .*running go (?<req_ver>.*);/

GO_MOD_VERSION = /^go 1\.\d+(\.\d+)?$/

sig do
Expand Down Expand Up @@ -292,6 +298,8 @@ def substitute_all(substitutions)
write_go_mod(body)
end

# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/PerceivedComplexity
sig { params(stderr: String).returns(T.noreturn) }
def handle_subprocess_error(stderr) # rubocop:disable Metrics/AbcSize
stderr = stderr.gsub(Dir.getwd, "")
Expand Down Expand Up @@ -323,10 +331,21 @@ def handle_subprocess_error(stderr) # rubocop:disable Metrics/AbcSize
raise Dependabot::OutOfDisk.new, error_message
end

if (matches = stderr.match(AMBIGUOUS_ERROR_MESSAGE))
raise Dependabot::DependencyFileNotResolvable, matches[:package]
end

if (matches = stderr.match(GO_VERSION_MISMATCH))
raise Dependabot::ToolVersionNotSupported.new(GO_LANG, T.must(matches[:current_ver]),
T.must(matches[:req_ver]))
end

# We don't know what happened so we raise a generic error
msg = stderr.lines.last(10).join.strip
raise Dependabot::DependabotError, msg
end
# rubocop:enable Metrics/AbcSize
# rubocop:enable Metrics/PerceivedComplexity

sig { params(message: String, regex: Regexp).returns(String) }
def filter_error_message(message:, regex:)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,35 @@
expect(error.message).to include("write error. Out of diskspace")
end
end

it "detects 'ambiguous package'" do
stderr = <<~ERROR
go: downloading google.golang.org/grpc v1.70.0
go: github.com/terraform-linters/tflint imports
github.com/terraform-linters/tflint/cmd imports
github.com/terraform-linters/tflint-ruleset-terraform/rules imports
github.com/hashicorp/go-getter imports
cloud.google.com/go/storage imports
google.golang.org: ambiguous import: found package google.golang.org/grpc/stats/otl in multiple modules:
google.golang.org/grpc v1.69.2 (/home/dependabot/go/pkg/mod/stats/opentelemetry)
ERROR

expect do
updater.send(:handle_subprocess_error, stderr)
end.to raise_error(Dependabot::DependencyFileNotResolvable)
end

it "detects 'ToolVersionNotSupported'" do
stderr = <<~ERROR
go: downloading google.golang.org/grpc v1.67.3
go: downloading google.golang.org/grpc v1.70.0
go: google.golang.org/grpc/stats/[email protected] requires go >= 1.22.7 (running go 1.22.5; CUAIN=local+auto)
ERROR

expect do
updater.send(:handle_subprocess_error, stderr)
end.to raise_error(Dependabot::ToolVersionNotSupported)
end
end
end
end
Loading