Skip to content

Commit

Permalink
Fixes Dependabot::SharedHelpers::HelperSubprocessFailed - err_pnpm_un…
Browse files Browse the repository at this point in the history
…supported_platform error code (#10436)

* Adds exception handler and test cases
  • Loading branch information
sachin-sandhu authored Aug 14, 2024
1 parent 8ac6c26 commit 5a79a6a
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ def updated_pnpm_lock_content(pnpm_lock)

ERR_PNPM_PATCH_NOT_APPLIED = /ERR_PNPM_PATCH_NOT_APPLIED/

# ERR_PNPM_UNSUPPORTED_PLATFORM
ERR_PNPM_UNSUPPORTED_PLATFORM = /ERR_PNPM_UNSUPPORTED_PLATFORM/
PLATFORM_PACAKGE_DEP = /Unsupported platform for (?<dep>.*)\: wanted/
PLATFORM_VERSION_REQUIREMENT = /wanted {(?<supported_ver>.*)} \(current: (?<detected_ver>.*)\)/
PLATFORM_PACAKGE_MANAGER = "pnpm"

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 @@ -145,6 +151,11 @@ def handle_pnpm_lock_updater_error(error, pnpm_lock)

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

if error_message.match?(ERR_PNPM_UNSUPPORTED_PLATFORM)
raise_unsupported_platform_error(error_message,
pnpm_lock)
end

raise
end
# rubocop:enable Metrics/AbcSize
Expand Down Expand Up @@ -201,6 +212,23 @@ def write_final_package_json_files
end
end

def raise_unsupported_platform_error(error_message, _pnpm_lock)
unless error_message.match(PLATFORM_PACAKGE_DEP) &&
error_message.match(PLATFORM_VERSION_REQUIREMENT)
return
end

supported_version = error_message.match(PLATFORM_VERSION_REQUIREMENT)
.named_captures["supported_ver"]
.then { sanitize_message(_1) }
detected_version = error_message.match(PLATFORM_VERSION_REQUIREMENT)
.named_captures["detected_ver"]
.then { sanitize_message(_1) }

Dependabot.logger.warn(error_message)
raise Dependabot::ToolVersionNotSupported.new(PLATFORM_PACAKGE_MANAGER, supported_version, detected_version)
end

def npmrc_content(pnpm_lock)
NpmrcBuilder.new(
credentials: credentials,
Expand Down Expand Up @@ -229,6 +257,10 @@ def base_dir
def npmrc_file
dependency_files.find { |f| f.name == ".npmrc" }
end

def sanitize_message(message)
message.gsub(/"|\[|\]|\}|\{/, "")
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,35 @@
end
end

context "with a registry resolution that returns err_pnpm_unsupported_platform response" do
let(:dependency_name) { "@swc/core-linux-arm-gnueabihf" }
let(:version) { "1.7.11" }
let(:previous_version) { "1.3.56" }
let(:requirements) do
[{
file: "package.json",
requirement: "1.7.11",
groups: ["optionalDependencies"],
source: nil
}]
end
let(:previous_requirements) do
[{
file: "package.json",
requirement: "1.3.56",
groups: ["optionalDependencies"],
source: nil
}]
end

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

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

context "when there is a private repo we don't have access to and returns a 4xx error" do
let(:project_name) { "pnpm/private_repo_no_access" }

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,21 @@
{
"name": "test",
"version": "1.1.1",
"private": true,
"pnpm": {
"supportedArchitectures": {
"os": ["win32", "darwin", "current"],
"cpu": ["arm"]
},
"requiredScripts": ["build"]
},
"dependencies": {
"@blocknote/core": "^0.15.3",
"@swc/core-linux-arm-gnueabihf": "1.3.56"
},
"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.

0 comments on commit 5a79a6a

Please sign in to comment.