Skip to content

Commit

Permalink
Fixes Subprocesshelperfailure issues
Browse files Browse the repository at this point in the history
  • Loading branch information
sachin-sandhu committed Jan 9, 2025
1 parent 0c65ca6 commit 8e121fd
Show file tree
Hide file tree
Showing 9 changed files with 5,653 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ def updated_pnpm_lock_content(pnpm_lock)
ERR_PNPM_LINKED_PKG_DIR_NOT_FOUND = /ERR_PNPM_LINKED_PKG_DIR_NOT_FOUND*.*Could not install from \"(?<dir>.*)\" /
ERR_PNPM_WORKSPACE_PKG_NOT_FOUND = /ERR_PNPM_WORKSPACE_PKG_NOT_FOUND/

# Unparsable package.json file
ERR_PNPM_INVALID_PACKAGE_JSON = /Invalid package.json in package/

# Unparsable lockfile
ERR_PNPM_UNEXPECTED_PKG_CONTENT_IN_STORE = /ERR_PNPM_UNEXPECTED_PKG_CONTENT_IN_STORE/
ERR_PNPM_OUTDATED_LOCKFILE = /ERR_PNPM_OUTDATED_LOCKFILE/

# Peer dependencies configuration error
ERR_PNPM_PEER_DEP_ISSUES = /ERR_PNPM_PEER_DEP_ISSUES/

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 @@ -196,6 +206,29 @@ def handle_pnpm_lock_updater_error(error, pnpm_lock)
raise Dependabot::DependencyFileNotResolvable, msg
end

if error_message.match?(ERR_PNPM_INVALID_PACKAGE_JSON)
msg = "Error while resolving package.json."
Dependabot.logger.warn(error_message)
raise Dependabot::DependencyFileNotResolvable, msg
end

[ERR_PNPM_UNEXPECTED_PKG_CONTENT_IN_STORE, ERR_PNPM_OUTDATED_LOCKFILE]
.each do |regexp|
next unless error_message.match?(regexp)

error_msg = T.let("Error while resolving pnpm-lock.yaml file.", String)

Dependabot.logger.warn(error_message)
raise Dependabot::DependencyFileNotResolvable, error_msg
end

if error_message.match?(ERR_PNPM_PEER_DEP_ISSUES)
msg = "Missing or invalid configuration while installing peer dependencies."

Dependabot.logger.warn(error_message)
raise Dependabot::DependencyFileNotResolvable, msg
end

raise_patch_dependency_error(error_message) if error_message.match?(ERR_PNPM_PATCH_NOT_APPLIED)

raise_unsupported_engine_error(error_message, pnpm_lock) if error_message.match?(ERR_PNPM_UNSUPPORTED_ENGINE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -592,5 +592,92 @@
.to raise_error(Dependabot::DependencyNotFound)
end
end

context "with a dependency resolution that returns Invalid package.json response" do
let(:dependency_name) { "@radix-ui/react-context-menu" }
let(:version) { "2.2.3-rc.12" }
let(:previous_version) { "^2.2.3" }
let(:requirements) do
[{
file: "package.json",
requirement: "2.2.3-rc.12",
groups: ["Dependencies"],
source: nil
}]
end
let(:previous_requirements) do
[{
file: "package.json",
requirement: "^2.2.3",
groups: ["Dependencies"],
source: nil
}]
end

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

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

context "with a dependency resolution that returns invalid YAML response" do
let(:dependency_name) { "@mdx-js/react" }
let(:version) { "3.0.2" }
let(:previous_version) { "^3.0.1" }
let(:requirements) do
[{
file: "package.json",
requirement: "3.0.2",
groups: ["Dependencies"],
source: nil
}]
end
let(:previous_requirements) do
[{
file: "package.json",
requirement: "^3.0.1",
groups: ["Dependencies"],
source: nil
}]
end

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

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

context "with a dependency resolution that returns unmet peer deps response" do
let(:dependency_name) { "clsx" }
let(:version) { "2.2.2" }
let(:previous_version) { "^2.1.1" }
let(:requirements) do
[{
file: "package.json",
requirement: "^2.1.1",
groups: ["peerDependencies"],
source: nil
}]
end
let(:previous_requirements) do
[{
file: "package.json",
requirement: "2.2.2",
groups: ["peerDependencies"],
source: nil
}]
end

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

it "raises a helpful error" do
expect { updated_pnpm_lock_content }
.to raise_error(Dependabot::DependencyFileNotResolvable)
end
end
end
end
26 changes: 26 additions & 0 deletions npm_and_yarn/spec/fixtures/projects/pnpm/invalid_json/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "xyz",
"version": "1.0.0",
"type": "module",
"private": true,
"license": "Creative Commons Attribution Non Commercial 3.0",
"dependencies": {
"@radix-ui/react-context-menu": "^2.2.3",
"ahqstore-types": "link:src-ahqstore-types\\pkg"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"repository": {
"type": "git",
"url": "https://github.com/abc/xyz"
},
"author": {
"name": "abc Softwares",
"email": "[email protected]",
"url": "https://github.com/abc"
}
}
Loading

0 comments on commit 8e121fd

Please sign in to comment.