Skip to content

Commit

Permalink
Fixes [1.2k weekly errors] [JS] exception handler for malformed packa…
Browse files Browse the repository at this point in the history
…ge manager version (#11274)

adds exception handler for malformed package manager version
  • Loading branch information
sachin-sandhu authored Jan 10, 2025
1 parent 768ddde commit b6e9029
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions npm_and_yarn/lib/dependabot/npm_and_yarn/package_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ def unsupported?
PNPMPackageManager::NAME => PNPMPackageManager
}.freeze, T::Hash[String, NpmAndYarnPackageManagerClassType])

# Error malformed version number string
ERROR_MALFORMED_VERSION_NUMBER = "Malformed version number"

class PackageManagerDetector
extend T::Sig
extend T::Helpers
Expand Down Expand Up @@ -520,6 +523,10 @@ def package_manager_by_name(name)
raw_version: installed_version,
requirement: package_manager_requirement
)
rescue ArgumentError => e
raise DependencyFileNotParseable, e.message if e.message.include?(ERROR_MALFORMED_VERSION_NUMBER)

raise
rescue StandardError => e
Dependabot.logger.error("Error resolving package manager for #{name || 'default'}: #{e.message}")
raise
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,14 @@
end
end
end

context "with a malformed packageManager" do
context "when package manager version is not specified correctly" do
it "returns the nil packageManager version" do
expect(helper.detect_version("npm^@1.2.3")).to be_nil
end
end
end
end

context "when packageManager field does not exist" do
Expand Down

0 comments on commit b6e9029

Please sign in to comment.