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

Handle php version mismatch error. #11703

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
25 changes: 21 additions & 4 deletions common/lib/dependabot/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,12 @@ def self.fetcher_error_details(error)
"error-type": "illformed_requirement",
"error-detail": { message: error.message }
}
when Dependabot::PhpVersionMismatchError
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can reuse some ToolVersion or existing error; tagging @kbukum1

{
"error-type": "php_version_mismatch_error",
"error-detail": { message: error.message }
}
when *Octokit::RATE_LIMITED_ERRORS
# If we get a rate-limited error we let dependabot-api handle the
# retry by re-enqueing the update job after the reset
{
"error-type": "octokit_rate_limited",
"error-detail": {
Expand Down Expand Up @@ -202,6 +205,11 @@ def self.parser_error_details(error)
# and responsibility for fixing it is on them, not us. As a result we
# quietly log these as errors
{ "error-type": "server_error" }
when Dependabot::PhpVersionMismatchError
{
"error-type": "php_version_mismatch_error",
"error-detail": { message: error.message }
}
end
end

Expand Down Expand Up @@ -362,9 +370,12 @@ def self.updater_error_details(error)
"error-type": "git_token_auth_error",
"error-detail": { message: error.message }
}
when Dependabot::PhpVersionMismatchError
{
"error-type": "php_version_mismatch_error",
"error-detail": { message: error.message }
}
when *Octokit::RATE_LIMITED_ERRORS
# If we get a rate-limited error we let dependabot-api handle the
# retry by re-enqueing the update job after the reset
{
"error-type": "octokit_rate_limited",
"error-detail": {
Expand Down Expand Up @@ -889,5 +900,11 @@ def initialize(message = nil)
super("network_unsafe_http", message)
end
end

class PhpVersionMismatchError < DependabotError
def initialize(message)
super("PHP version mismatch: #{message}")
end
end
end
# rubocop:enable Metrics/ModuleLength
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,12 @@ def handle_composer_errors(error)
raise PrivateSourceAuthenticationFailure, "nova.laravel.com"
end

# To handle the case where the PHP version (configured in composer.json) is not supported
# Your requirements could not be resolved to an installable set of packages.
# Problem 1
# - Root composer.json requires league/csv >= 9.7, == 9.22.0 -> satisfiable by league/csv[9.22.0].
raise PhpVersionMismatchError, error.message if error.message.include?("your php version")

dependency_url = Helpers.dependency_url_from_git_clone_error(error.message)
if dependency_url
raise Dependabot::GitDependenciesNotReachable, dependency_url
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,23 @@
end
end

context "with an application using a ^ PHP constraint and encountering a PhpVersionMismatchError" do
context "when the minimum version is invalid" do
let(:project_name) { "php_specified_min_invalid_without_lockfile_handle_error" }
let(:dependency_name) { "phpdocumentor/reflection-docblock" }
let(:dependency_version) { "2.0.4" }
let(:string_req) { "2.0.4" }
let(:latest_allowable_version) { Gem::Version.new("3.2.2") }

it "raises a Dependabot::PhpVersionMismatchError error" do
expect { resolver.latest_resolvable_version }
.to raise_error(Dependabot::PhpVersionMismatchError) do |error|
expect(error.message).to include("PHP version mismatch: Your requirements could not be resolved")
end
end
end
end

context "when updating a subdependency that's not required anymore" do
let(:project_name) { "subdependency_no_longer_required" }
let(:requirements) { [] }
Expand Down
5 changes: 5 additions & 0 deletions composer/spec/fixtures/projects/conflicts/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,10 @@
"psr-4": {
"Tests\\Tsufeki\\KayoJsonMapper\\": "tests/Tsufeki/KayoJsonMapper/"
}
},
"config": {
"platform": {
"php": "7.1.3"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@
"php": "^5.2.0",
"phpdocumentor/reflection-docblock": "2.0.4",
"illuminate/support": "^5.2.0"
},
"config": {
"platform": {
"php": "5.8.36"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"require": {
"php": "^5.2.0",
"phpdocumentor/reflection-docblock": "2.0.4",
"illuminate/support": "^5.2.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@
"php": ">=5.6.0",
"phpdocumentor/reflection-docblock": "2.0.4",
"illuminate/support": "^5.2.0"
},
"config": {
"platform": {
"php": "5.8.36"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@
"test": "vendor/bin/phpunit"
},
"config": {
"sort-packages": true
"sort-packages": true,
"platform": {
"php": "7.1.3"
}
},
"extra": {
"laravel": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,10 @@
},
"require-dev": {
"phpunit/phpunit": "^4.0 || ^8.0"
},
"config": {
"platform": {
"php": "5.8.36"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@
"phalcon/devtools": "~3.2",
"longman/telegram-bot": "*",
"james-heinrich/getid3": "^1.9"
},
"config": {
"platform": {
"php": "8.2.27"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@
"phalcon/devtools": "~3.2",
"longman/telegram-bot": "*",
"james-heinrich/getid3": "^1.9"
},
"config": {
"platform": {
"php": "8.2.27"
}
}
}
Loading