Skip to content

Commit

Permalink
Adds error handler for Ruby version not found class error
Browse files Browse the repository at this point in the history
  • Loading branch information
sachin-sandhu committed Jan 22, 2025
1 parent 9451c2e commit bd0560c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
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

0 comments on commit bd0560c

Please sign in to comment.