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

Add Error Handling for YN0082 in YarnErrorHandler #10374

Merged
merged 2 commits into from
Aug 5, 2024
Merged
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
14 changes: 14 additions & 0 deletions npm_and_yarn/lib/dependabot/npm_and_yarn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ module NpmAndYarn
FAILED_TO_RETRIEVE: %r{(?<package_req>@[\w-]+\/[\w-]+@\S+): The remote server failed to provide the requested resource} # rubocop:disable Layout/LineLength
}.freeze, T::Hash[String, Regexp])

YN0082_PACKAGE_NOT_FOUND_REGEX = /YN0082:.*?(\S+@\S+): No candidates found/

PACKAGE_NOT_FOUND2 = %r{/[^/]+: Not found}
PACKAGE_NOT_FOUND2_PACKAGE_NAME_REGEX = %r{/(?<package_name>[^/]+): Not found}
PACKAGE_NOT_FOUND2_PACKAGE_NAME_CAPTURE = "package_name"
Expand Down Expand Up @@ -241,6 +243,18 @@ def self.sanitize_resolvability_message(error_message, dependencies, yarn_lock)
handler: lambda { |message, _error, _params|
Dependabot::NetworkUnsafeHTTP.new(message)
}
},
"YN0082" => {
message: "No candidates found",
handler: lambda { |message, _error, _params|
match_data = message.match(YN0082_PACKAGE_NOT_FOUND_REGEX)
if match_data
package_req = match_data[1]
Dependabot::DependencyNotFound.new("#{package_req} Detail: #{message}")
else
Dependabot::DependencyNotFound.new(message)
end
}
}
}.freeze, T::Hash[String, {
message: T.any(String, NilClass),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,25 @@
)
end
end

context "when the error message contains YN0082" do
let(:error_message) do
"➤ YN0000: · Yarn 4.3.1\n" \
"➤ YN0000: ┌ Resolution step\n::group::Resolution step\n" \
"➤ YN0082: │ string-width-cjs@npm:^4.2.3: " \
"No candidates found\n::endgroup::\n" \
"➤ YN0082: string-width-cjs@npm:^4.2.3: " \
"No candidates found\n" \
"➤ YN0000: └ Completed\n" \
"➤ YN0000: · Failed with errors in 0s 158ms"
end

it "raises a DependencyNotFound error with the correct message" do
expect do
error_handler.handle_error(error, { yarn_lock: yarn_lock })
end.to raise_error(Dependabot::DependencyNotFound, /string-width-cjs@npm:\^4.2.3/)
end
end
end

describe "#find_usage_error" do
Expand Down Expand Up @@ -288,6 +307,25 @@
end
end
end

context "when the error message contains YN0082" do
let(:error_message) do
"➤ YN0000: · Yarn 4.3.1\n" \
"➤ YN0000: ┌ Resolution step\n::group::Resolution step\n" \
"➤ YN0082: │ string-width-cjs@npm:^4.2.3: " \
"No candidates found\n::endgroup::\n" \
"➤ YN0082: string-width-cjs@npm:^4.2.3: " \
"No candidates found\n" \
"➤ YN0000: └ Completed\n" \
"➤ YN0000: · Failed with errors in 0s 158ms"
end

it "raises a DependencyNotFound error with the correct message" do
expect do
error_handler.handle_yarn_error(error, { yarn_lock: yarn_lock })
end.to raise_error(Dependabot::DependencyNotFound, /string-width-cjs@npm:\^4.2.3/)
end
end
end

describe "#handle_group_patterns" do
Expand Down
Loading