Skip to content

Commit

Permalink
Handle invalid major version errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mctofu committed Nov 19, 2021
1 parent 464bf15 commit 1d5a203
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class LatestVersionFinder
# (Private) module could not be fetched
/module .*: git ls-remote .*: exit status 128/m.freeze
].freeze
INVALID_VERSION_REGEX = /version "[^"]+" invalid/m.freeze
PSEUDO_VERSION_REGEX = /\b\d{14}-[0-9a-f]{12}$/.freeze

def initialize(dependency:, dependency_files:, credentials:,
Expand Down Expand Up @@ -108,6 +109,8 @@ def available_versions
def handle_subprocess_error(error)
if RESOLVABILITY_ERROR_REGEXES.any? { |rgx| error.message =~ rgx }
ResolvabilityErrors.handle(error.message, credentials: credentials)
elsif INVALID_VERSION_REGEX =~ error.message
raise Dependabot::DependencyFileNotResolvable, error.message
end

raise
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,34 @@ module foobar
end
end

context "when the dependency's major version is invalid because it's not specified in its go.mod" do
let(:dependency_name) { "github.com/dependabot-fixtures/go-modules-lib/v2" }
let(:dependency_version) { "2.0.0" }

it "raises a DependencyFileNotResolvable error" do
error_class = Dependabot::DependencyFileNotResolvable
expect { finder.latest_version }.
to raise_error(error_class) do |error|
expect(error.message).to include("github.com/dependabot-fixtures/go-modules-lib/v2")
expect(error.message).to include("version \"v2.0.0\" invalid")
end
end
end

context "when the dependency's major version is invalid because not properly imported" do
let(:dependency_name) { "github.com/dependabot-fixtures/go-modules-lib" }
let(:dependency_version) { "3.0.0" }

it "raises a DependencyFileNotResolvable error" do
error_class = Dependabot::DependencyFileNotResolvable
expect { finder.latest_version }.
to raise_error(error_class) do |error|
expect(error.message).to include("github.com/dependabot-fixtures/go-modules-lib")
expect(error.message).to include("version \"v3.0.0\" invalid")
end
end
end

context "when the module is unreachable" do
let(:dependency_files) { [go_mod] }
let(:dependency_name) { "github.com/dependabot-fixtures/go-modules-private" }
Expand Down

0 comments on commit 1d5a203

Please sign in to comment.