Skip to content

Commit

Permalink
Fixes Dependabot::Updater::SubprocessFailed issues (#10555)
Browse files Browse the repository at this point in the history
* Adds exception handlers
  • Loading branch information
sachin-sandhu authored Sep 10, 2024
1 parent e82197c commit cc58403
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 0 deletions.
12 changes: 12 additions & 0 deletions npm_and_yarn/lib/dependabot/npm_and_yarn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ module NpmAndYarn
AUTH_ERROR: /YN0001:*.*Fatal Error: could not read Username for '(?<url>.*)': terminal prompts disabled/
}.freeze, T::Hash[String, Regexp])

YN0001_REQ_NOT_FOUND_CODES = T.let({
REQUIREMENT_NOT_SATISFIED: /provides (?<dep>.*)(.*?)with version (?<ver>.*), which doesn't satisfy what (?<pkg>.*) requests/, # rubocop:disable Layout/LineLength
REQUIREMENT_NOT_PROVIDED: /(?<dep>.*)(.*?)doesn't provide (?<pkg>.*)(.*?), requested by (?<parent>.*)/
}.freeze, T::Hash[String, Regexp])

class Utils
extend T::Sig

Expand Down Expand Up @@ -212,6 +217,13 @@ def self.sanitize_resolvability_message(error_message, dependencies, yarn_lock)
return Dependabot::PrivateSourceAuthenticationFailure.new(url)
end
end

YN0001_REQ_NOT_FOUND_CODES.each do |(_yn0001_key, yn0001_regex)|
if (msg = message.match(yn0001_regex))
return Dependabot::DependencyFileNotResolvable.new(msg)
end
end

Dependabot::DependabotError.new(message)
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ def fetch_npm_response
password: password
}
)
rescue URI::InvalidURIError => e
raise DependencyFileNotResolvable, e.message
end

def check_npm_response(npm_response)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ def first_registry_with_dependency_details
Excon::Error::Socket,
JSON::ParserError
nil
rescue URI::InvalidURIError => e
raise DependencyFileNotResolvable, e.message
end&.fetch("registry")

@first_registry_with_dependency_details ||= global_registry.sub(%r{/+$}, "").sub(%r{^.*?//}, "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,22 @@
end
end
end

context "when the npm registry uri is invalid and lookup returns a bad URI error" do
before do
stub_request(:get, registry_listing_url)
.to_return(status: 500, body: '{"error":"bad URI(is not URI?): "https://registry.npmjs.org/\"/webpack""}')

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(Dependabot::DependencyFileNotResolvable)
end
end
end
end

describe "#latest_version_with_no_unlock" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,20 @@
end
end

context "when the error message contains requirement not specified error" do
let(:error_message) do
"[YN0001]: Exception error, Detail: ➤ YN0000: ┌ Resolution step" \
"kubernetes-dashboard@workspace:. provides @angular/core (pc7ae5) with version 16.2.1, which doesn't satisfy what codelyzer requests" # rubocop:disable Layout/LineLength
end

it "raises a DependencyFileNotResolvable error with the correct message" do
expect do
error_handler.handle_yarn_error(error, { yarn_lock: yarn_lock })
end.to raise_error(Dependabot::DependencyFileNotResolvable,
"provides @angular/core (pc7ae5) with version 16.2.1, which doesn't satisfy what codelyzer requests") # rubocop:disable Layout/LineLength
end
end

context "when the error message contains YN0041 response (Invalid authentication)" do
let(:error_message) do
"[91m➤ YN0041: │ @cadence-group/conventional-changelog-angular-" \
Expand Down

0 comments on commit cc58403

Please sign in to comment.