Skip to content

Commit

Permalink
Fixes unhandled couldn't find any versions for package exception (#10491
Browse files Browse the repository at this point in the history
)

* fixes instance of package version not found error
  • Loading branch information
sachin-sandhu authored Aug 23, 2024
1 parent 4c559b9 commit 1121a33
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
15 changes: 15 additions & 0 deletions npm_and_yarn/lib/dependabot/npm_and_yarn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ module NpmAndYarn
YARNRC_ENOENT = /Internal Error: ENOENT/
YARNRC_ENOENT_REGEX = /Internal Error: ENOENT: no such file or directory, stat '(?<filename>.*?)'/

# if not package found with specified version
YARN_PACKAGE_NOT_FOUND = /MessageError: Couldn't find any versions for "(?<pkg>.*?)" that matches "(?<ver>.*?)"/

YN0001_FILE_NOT_RESOLVED_CODES = T.let({
FIND_PACKAGE_LOCATION: /YN0001: UsageError: Couldn't find the (?<pkg>.*) state file/,
NO_CANDIDATE_FOUND: /YN0001: Error: (?<pkg>.*): No candidates found/,
Expand Down Expand Up @@ -477,6 +480,18 @@ def self.sanitize_resolvability_message(error_message, dependencies, yarn_lock)
},
in_usage: false,
matchfn: nil
},
{
patterns: [YARN_PACKAGE_NOT_FOUND],
handler: lambda { |message, _error, _params|
package_name = message.match(YARN_PACKAGE_NOT_FOUND).named_captures["pkg"]
version = message.match(YARN_PACKAGE_NOT_FOUND).named_captures["ver"]

Dependabot::InconsistentRegistryResponse.new("Couldn't find any versions for \"#{package_name}\" that " \
"matches \"#{version}\"")
},
in_usage: false,
matchfn: nil
}

].freeze, T::Array[{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,21 @@
end
end

context "when the error message contains no specified version for package error" do
let(:error_message) do
"MessageError: Couldn't find any versions for \"@types/react-test-renderer\" that matches \"~18.2.0\"" \
"at /opt/npm_and_yarn/node_modules/@dependabot/yarn-lib/lib/resolvers/registries/npm-resolver.js:120:13
at Generator.next (<anonymous>)"
end

it "raises a DependencyFileNotResolvable error with the correct message" do
expect { error_handler.handle_error(error, { yarn_lock: yarn_lock }) }
.to raise_error(Dependabot::InconsistentRegistryResponse,
"Couldn't find any versions for \"@types/react-test-renderer\" that " \
"matches \"~18.2.0\"")
end
end

context "when the error message contains YN0001 response (could not read Username)" do
let(:error_message) do
"➤ YN0000: ┌ Resolution step
Expand Down

0 comments on commit 1121a33

Please sign in to comment.