diff --git a/python/lib/dependabot/python/update_checker/poetry_version_resolver.rb b/python/lib/dependabot/python/update_checker/poetry_version_resolver.rb index bf5ed4032a..fbc6b04ad6 100644 --- a/python/lib/dependabot/python/update_checker/poetry_version_resolver.rb +++ b/python/lib/dependabot/python/update_checker/poetry_version_resolver.rb @@ -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 (?.*) for (?.*) does not exist/ + sig do params( dependencies: Dependabot::Dependency, @@ -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) || @@ -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) diff --git a/python/spec/dependabot/python/update_checker/poetry_version_resolver_spec.rb b/python/spec/dependabot/python/update_checker/poetry_version_resolver_spec.rb index e0f105977d..79fd21159d 100644 --- a/python/spec/dependabot/python/update_checker/poetry_version_resolver_spec.rb +++ b/python/spec/dependabot/python/update_checker/poetry_version_resolver_spec.rb @@ -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 @@ -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