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

Adds error handler for Ruby version not found class error #11362

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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 @@ -9,8 +9,6 @@ module Dependabot
module Bundler
class FileUpdater
class RubyRequirementSetter
class RubyVersionNotFound < StandardError; end

RUBY_VERSIONS = %w(
1.8.7 1.9.3 2.0.0 2.1.10 2.2.10 2.3.8 2.4.10 2.5.9 2.6.9 2.7.6 3.0.6 3.1.6 3.2.4 3.3.6
).freeze
Expand Down Expand Up @@ -62,7 +60,7 @@ def ruby_version
.map { |v| Gem::Version.new(v) }.sort
.find { |v| requirement.satisfied_by?(v) }

raise RubyVersionNotFound unless ruby_version
raise RubyVersionNotFound, requirement.to_s unless ruby_version

ruby_version
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
bundler_project_dependency_file("gemfile_impossible_ruby", filename: "example.gemspec")
end

specify { expect { rewrite }.to raise_error(described_class::RubyVersionNotFound) }
specify { expect { rewrite }.to raise_error(Dependabot::RubyVersionNotFound) }
end

context "when requiring ruby 3" do
Expand Down
19 changes: 19 additions & 0 deletions common/lib/dependabot/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,11 @@ def self.updater_error_details(error)
"error-type": "git_token_auth_error",
"error-detail": { message: error.message }
}
when RubyVersionNotFound
{
"error-type": "ruby_version_not_found",
"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
Expand Down Expand Up @@ -605,6 +610,20 @@ class DependencyFileNotResolvable < DependabotError; end

class BadRequirementError < Gem::Requirement::BadRequirementError; end

class RubyVersionNotFound < DependabotError
extend T::Sig

sig { returns(String) }
attr_reader :ruby_version

sig { params(ruby_version: String).void }
def initialize(ruby_version)
@ruby_version = T.let(ruby_version, String)

super("Unsupported ruby version \"#{@ruby_version}\" while updating the Gemfile.")
end
end

#######################
# Source level errors #
#######################
Expand Down
Loading