Skip to content

Commit

Permalink
Fixes Dependabot::SharedHelpers::HelperSubprocessFailed - ERR_PNPM_UN…
Browse files Browse the repository at this point in the history
…SUPPORTED_ENGINE (#10419)

* adds exception handler for PNPM_UNSUPPORTED_ENGINE
  • Loading branch information
sachin-sandhu authored Aug 13, 2024
1 parent 4bbcea3 commit f71537d
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ def updated_pnpm_lock_content(pnpm_lock)
ERR_PNPM_FETCH_500 = /ERR_PNPM_FETCH_500.*GET (?<dependency_url>.*): - 500/
ERR_PNPM_FETCH_502 = /ERR_PNPM_FETCH_502.*GET (?<dependency_url>.*): - 502/

# ERR_PNPM_UNSUPPORTED_ENGINE
ERR_PNPM_UNSUPPORTED_ENGINE = /ERR_PNPM_UNSUPPORTED_ENGINE/
PACAKGE_MANAGER = /Your (?<pkg_mgr>.*) version is incompatible with/
VERSION_REQUIREMENT = /Expected version: (?<supported_ver>.*)\nGot: (?<detected_ver>.*)\n/

def run_pnpm_update(pnpm_lock:)
SharedHelpers.in_a_temporary_repo_directory(base_dir, repo_contents_path) do
File.write(".npmrc", npmrc_content(pnpm_lock))
Expand Down Expand Up @@ -121,6 +126,8 @@ def handle_pnpm_lock_updater_error(error, pnpm_lock)
raise_package_access_error(error_message, dependency_url, pnpm_lock)
end

raise_unsupported_engine_error(error_message, pnpm_lock) if error_message.match?(ERR_PNPM_UNSUPPORTED_ENGINE)

raise
end

Expand All @@ -131,6 +138,19 @@ def raise_resolvability_error(error_message, pnpm_lock)
raise Dependabot::DependencyFileNotResolvable, msg
end

def raise_unsupported_engine_error(error_message, _pnpm_lock)
unless error_message.match(PACAKGE_MANAGER) &&
error_message.match(VERSION_REQUIREMENT)
return
end

package_manager = error_message.match(PACAKGE_MANAGER).named_captures["pkg_mgr"]
supported_version = error_message.match(VERSION_REQUIREMENT).named_captures["supported_ver"]
detected_version = error_message.match(VERSION_REQUIREMENT).named_captures["detected_ver"]

raise Dependabot::ToolVersionNotSupported.new(package_manager, supported_version, detected_version)
end

def raise_package_access_error(error_message, dependency_url, pnpm_lock)
package_name = RegistryParser.new(resolved_url: dependency_url, credentials: credentials).dependency_name
missing_dep = lockfile_dependencies(pnpm_lock)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,69 @@
end
end

context "when there is a unsupported engine response from registry" do
let(:dependency_name) { "@blocknote/core" }
let(:version) { "0.15.4" }
let(:previous_version) { "0.15.3 " }
let(:requirements) do
[{
file: "package.json",
requirement: "0.15.4",
groups: ["dependencies"],
source: nil
}]
end

let(:project_name) { "pnpm/unsupported_engine" }

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

context "when there is a unsupported engine (npm) response from registry" do
let(:dependency_name) { "@npmcli/fs" }
let(:version) { "3.1.1" }
let(:previous_version) { "3.1.0 " }
let(:requirements) do
[{
file: "package.json",
requirement: "3.1.1",
groups: ["devDependencies"],
source: nil
}]
end

let(:project_name) { "pnpm/unsupported_engine_npm" }

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

context "when there is a unsupported engine response (pnpm) from registry" do
let(:dependency_name) { "eslint" }
let(:version) { "9.9.0" }
let(:previous_version) { "8.32.0" }
let(:requirements) do
[{
file: "package.json",
requirement: "9.9.0",
groups: ["devDependencies"],
source: nil
}]
end

let(:project_name) { "pnpm/unsupported_engine_pnpm" }

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

context "with a dependency that can't be found" do
let(:project_name) { "pnpm/nonexistent_dependency_yanked_version" }

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
engine-strict=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "test",
"version": "1.1.1",
"private": true,
"dependencies": {
"@blocknote/core": "^0.15.3"
},
"engines": {
"pnpm": ">=8.0.0 <11.0.0",
"node": ">=18.0.0 <19.0.0"
},
"packageManager": "pnpm@8.4.0+sha1.73c608c602d520c436c7b250330315d83ffcc1ee"
}

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 @@
engine-strict=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

{
"name": "name",
"version": "0.0.0",
"private": true,
"devDependencies": {
"@npmcli/fs": "3.1.0"
},
"engines": {
"node": "20.11.1",
"npm": "use pnpm",
"pnpm": ">=9",
"yarn": "use pnpm"
}
}

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,5 @@
strict-peer-dependencies=false
engine-strict=true
registry=https://registry.npmjs.org/
hoist-pattern[]=*eslint*
use-node-version=18.0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "abc",
"packageManager": "pnpm@8.15.1",
"engines": {
"node": "^14.16.0 || ^16.10.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^20.0.0"
},
"devDependencies": {
"eslint": "^8.32.0"
}
}

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

0 comments on commit f71537d

Please sign in to comment.