Skip to content

Commit

Permalink
Fixes issues with Dependabot::SharedHelpers::HelperSubprocessFailed -…
Browse files Browse the repository at this point in the history
… Python (#10615)

* adds exception handlers for poetry
  • Loading branch information
sachin-sandhu authored Sep 17, 2024
1 parent a602925 commit 989987b
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,15 @@ def normalise(name)
class PoetryErrorHandler < UpdateChecker
extend T::Sig

# if a valid config value is not found in project.toml file
INVALID_CONFIGURATION = /The Poetry configuration is invalid:(?<config>.*)/

# if .toml has incorrect version specification i.e. <0.2.0app
INVALID_VERSION = /Could not parse version constraint: (?<ver>.*)/

# dependency source link not accessible
INVALID_LINK = /No valid distribution links found for package: "(?<dep>.*)" version: "(?<ver>.*)"/

sig do
params(
dependencies: Dependabot::Dependency,
Expand All @@ -361,9 +370,14 @@ def initialize(dependencies:, dependency_files:)

sig { params(error: Exception).void }
def handle_poetry_error(error)
return true unless (msg = error.message.match(PoetryVersionResolver::INCOMPATIBLE_CONSTRAINTS))
Dependabot.logger.warn(error.message)

raise DependencyFileNotResolvable, msg
if (msg = error.message.match(PoetryVersionResolver::INCOMPATIBLE_CONSTRAINTS) ||
error.message.match(INVALID_CONFIGURATION) || error.message.match(INVALID_VERSION) ||
error.message.match(INVALID_LINK))

raise DependencyFileNotResolvable, msg
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,5 +395,48 @@
end
end
end

context "with invalid configuration in pyproject.toml file" do
let(:response) do
"The Poetry configuration is invalid:
- data.group.dev.dependencies.h5 must be valid exactly by one definition (0 matches found)"
end

it "raises a helpful error" do
expect { poetry_error_handler }.to raise_error(Dependabot::DependencyFileNotResolvable) do |error|
expect(error.message)
.to include("The Poetry configuration is invalid")
end
end
end

context "with invalid version for dependency mentioned in pyproject.toml file" do
let(:response) do
"Resolving dependencies...
Could not parse version constraint: <0.2.0app"
end

it "raises a helpful error" do
expect { poetry_error_handler }.to raise_error(Dependabot::DependencyFileNotResolvable) do |error|
expect(error.message)
.to include("Could not parse version constraint: <0.2.0app")
end
end
end

context "with invalid dependency source link in pyproject.toml file" do
let(:response) do
"Updating dependencies
Resolving dependencies...
No valid distribution links found for package: \"llama-cpp-python\" version: \"0.2.82\""
end

it "raises a helpful error" do
expect { poetry_error_handler }.to raise_error(Dependabot::DependencyFileNotResolvable) do |error|
expect(error.message)
.to include("No valid distribution links found for package: \"llama-cpp-python\" version: \"0.2.82\"")
end
end
end
end
end

0 comments on commit 989987b

Please sign in to comment.