Skip to content

Commit

Permalink
raise specific error when no update was possible (#10685)
Browse files Browse the repository at this point in the history
  • Loading branch information
brettfo authored Sep 26, 2024
1 parent dddd7b2 commit 60e6cba
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
22 changes: 22 additions & 0 deletions common/lib/dependabot/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,13 @@ def self.updater_error_details(error)
"go-mod": error.go_mod
}
}
when Dependabot::UpdateNotPossible
{
"error-type": "update_not_possible",
"error-detail": {
dependencies: error.dependencies
}
}
when BadRequirementError
{
"error-type": "illformed_requirement",
Expand Down Expand Up @@ -639,6 +646,21 @@ class InconsistentRegistryResponse < DependabotError; end
# Dependency level errors #
###########################

class UpdateNotPossible < DependabotError
extend T::Sig

sig { returns(T::Array[String]) }
attr_reader :dependencies

sig { params(dependencies: T::Array[String]).void }
def initialize(dependencies)
@dependencies = dependencies

msg = "The following dependencies could not be updated: #{@dependencies.join(', ')}"
super(msg)
end
end

class GitDependenciesNotReachable < DependabotError
extend T::Sig

Expand Down
6 changes: 5 additions & 1 deletion nuget/lib/dependabot/nuget/file_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def self.differs_in_more_than_blank_lines?(original_content, updated_content)
sig { override.returns(T::Array[Dependabot::DependencyFile]) }
def updated_dependency_files
base_dir = "/"
SharedHelpers.in_a_temporary_repo_directory(base_dir, repo_contents_path) do
all_updated_files = SharedHelpers.in_a_temporary_repo_directory(base_dir, repo_contents_path) do
dependencies.each do |dependency|
try_update_projects(dependency) || try_update_json(dependency)
end
Expand All @@ -70,6 +70,10 @@ def updated_dependency_files
end
updated_files
end

raise UpdateNotPossible, dependencies.map(&:name) if all_updated_files.empty?

all_updated_files
end

private
Expand Down
21 changes: 21 additions & 0 deletions nuget/spec/dependabot/nuget/file_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,27 @@ def intercept_native_tools(discovery_content_hash:)
end
end
end

context "when no update is performed" do
let(:dependency) do
Dependabot::Dependency.new(
name: "This.Dependency.Does.Not.Exist",
version: "4.5.6",
previous_version: "1.2.3",
requirements: [{ file: "Proj1/Proj1/Proj1.csproj", requirement: "4.5.6", groups: [], source: nil }],
previous_requirements: [{ file: "Proj1/Proj1/Proj1.csproj", requirement: "1.2.3", groups: [], source: nil }],
package_manager: "nuget"
)
end

it "raises the expected error" do
run_update_test do |updater|
expect do
updater.updated_dependency_files
end.to raise_error(Dependabot::UpdateNotPossible)
end
end
end
end

describe "#updated_dependency_files_with_wildcard" do
Expand Down

0 comments on commit 60e6cba

Please sign in to comment.