Skip to content

Commit

Permalink
Fixes issues related with Dependabot::NpmAndYarn::UpdateChecker::Late…
Browse files Browse the repository at this point in the history
…stVersionFinder::RegistryError (#10322)

* Handles inconsistent response from registry
  • Loading branch information
sachin-sandhu authored Aug 1, 2024
1 parent 15ee538 commit 7ea926f
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,29 @@
end
end

context "with a registry package lookup that returns a 404" do
let(:files) { project_dependency_files("npm/simple_with_no_access_registry") }
let(:dependency_name) { "@gcorevideo/rtckit" }
let(:version) { "3.3.1" }
let(:previous_version) { "^3.3.0" }
let(:requirements) do
[{
file: "package.json",
requirement: "^3.3.0",
groups: ["dependencies"],
source: {
type: "registry",
url: "http://npmrepo.nl"
}
}]
end
let(:previous_requirements) { requirements }

it "raises a helpful error" do
expect { updated_npm_lock_content }.to raise_error(Dependabot::DependencyFileNotResolvable)
end
end

context "with a dependency with nested aliases not supported" do
let(:files) { project_dependency_files("npm/simple_with_nested_deps") }
let(:dependency_name) { "express" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,23 @@
end
end

context "when the npm registry package lookup returns a 404 error" do
before do
stub_request(:get, registry_listing_url)
.to_return(status: 404, body: '{"error":"Not found"}')

allow(version_finder).to receive(:sleep).and_return(true)
end

it "raises an error" do
expect { version_finder.latest_version_from_registry }
.to raise_error do |err|
expect(err.class).to eq(described_class::RegistryError)
expect(err.status).to eq(404)
end
end
end

context "when the dependency has been deprecated" do
let(:registry_response) do
fixture("npm_responses", "etag_deprecated.json")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
engine-strict=true
@gcore:registry = "http://npmrepo.nl"

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "xyz",
"version": "0.1.0",
"main": "index.js",
"author": "abc",
"license": "ISC",
"description": "",
"devDependencies": {
},
"dependencies": {
"@gcorevideo/rtckit": "^0.61.0"
}
}
11 changes: 10 additions & 1 deletion updater/lib/dependabot/updater/operations/update_all_versions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def check_and_create_pr_with_error_handling(dependency)
error_detail: e.message
)
rescue StandardError => e
error_handler.handle_dependency_error(error: e, dependency: dependency)
process_dependency_error(e, dependency)
end

# rubocop:disable Metrics/AbcSize
Expand Down Expand Up @@ -181,6 +181,15 @@ def log_checking_for_update(dependency)
job.log_ignore_conditions_for(dependency)
end

def process_dependency_error(error, dependency)
if error.class.to_s.include?("RegistryError")
ex = Dependabot::DependencyFileNotResolvable.new(error.message)
error_handler.handle_dependency_error(error: ex, dependency: dependency)
else
error_handler.handle_dependency_error(error: error, dependency: dependency)
end
end

def all_versions_ignored?(dependency, checker)
Dependabot.logger.info("Latest version is #{checker.latest_version}")
false
Expand Down

0 comments on commit 7ea926f

Please sign in to comment.