Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft pip unhandled exception handling #11273

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -364,11 +364,18 @@ class PoetryErrorHandler < UpdateChecker

# server response error codes while accessing package index
SERVER_ERROR_CODES = T.let({
server500: /500 Server Error/,
server502: /502 Server Error/,
server503: /503 Server Error/,
server504: /504 Server Error/
}.freeze, T::Hash[T.nilable(String), Regexp])

# invalid configuration in pyproject.toml
POETRY_VIRTUAL_ENV_CONFIG = %r{pypoetry/virtualenvs(.|\n)*list index out of range}

# error related to local project as dependency in pyproject.toml
ERR_LOCAL_PROJECT_PATH = /Path (?<path>.*) for (?<dep>.*) does not exist/

sig do
params(
dependencies: Dependabot::Dependency,
Expand Down Expand Up @@ -403,6 +410,7 @@ def sanitize_url(url)
# rubocop:disable Metrics/PerceivedComplexity
sig { params(error: Exception).void }
def handle_poetry_error(error)
debugger
Dependabot.logger.warn(error.message)

if (msg = error.message.match(PoetryVersionResolver::INCOMPATIBLE_CONSTRAINTS) ||
Expand All @@ -418,6 +426,12 @@ def handle_poetry_error(error)

raise DependencyFileNotResolvable, error.message if error.message.match(PYTHON_RANGE_NOT_SATISFIED)

if error.message.match(POETRY_VIRTUAL_ENV_CONFIG) || error.message.match(ERR_LOCAL_PROJECT_PATH)
msg = "Error while resolving pyproject.toml file"

raise DependencyFileNotResolvable, msg
end

SERVER_ERROR_CODES.each do |(_error_codes, error_regex)|
next unless error.message.match?(error_regex)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,22 @@
end
end

context "with private registry authentication 504 Server Error" do
let(:response) do
"Creating virtualenv pylossmap-m4-85W1Y-py3.13 in /home/dependabot/.cache/pypoetry/virtualenvs
Updating dependencies
Resolving dependencies...

500 Server Error: Internal Server Error for url: http://acc-py-repo.cern.ch:8081/repository/vr-py-releases/simple/jinja2/"
end
it "raises a helpful error" do
expect { poetry_error_handler }.to raise_error(Dependabot::InconsistentRegistryResponse) do |error|
expect(error.message)
.to include("http://acc-py-repo.cern.ch")
end
end
end

context "with private registry authentication 504 Server Error" do
let(:response) do
"Creating virtualenv alk-service-import-product-TbrdR40A-py3.8 in /home/dependabot/.cache/pypoetry/virtualenvs
Expand Down Expand Up @@ -550,5 +566,32 @@
end
end
end

context "with a misconfigured pyproject.toml file" do
let(:response) do
"Creating virtualenv analysis-nlUUV3qa-py3.13 in pypoetry/virtualenvs
Updating dependencies
Resolving dependencies...
list index out of range"
end

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

context "with a project is listed a dependency" do
let(:response) do
"Creating virtualenv kiota-serialization-multipart-GzD6BRdm-py3.13 in " \
"/home/dependabot/.cache/pypoetry/virtualenvs" \
"Updating dependencies" \
"Resolving dependencies..." \
"Path tmp/20250109-1637-dc4aky/json for kiota-serialization-json does not exist"
end

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