From f78bc2db3c764bc4b564a1197702ae5ff49b5424 Mon Sep 17 00:00:00 2001 From: James Titcumb Date: Fri, 10 Jul 2026 19:52:21 +0100 Subject: [PATCH] 585: improve messaging when no auth available during verify --- src/SelfManage/Verify/FailedToVerifyRelease.php | 13 +++++++++++++ .../Verify/FallbackVerificationUsingOpenSsl.php | 7 +++++++ 2 files changed, 20 insertions(+) diff --git a/src/SelfManage/Verify/FailedToVerifyRelease.php b/src/SelfManage/Verify/FailedToVerifyRelease.php index 6ecaa67e..305bd25d 100644 --- a/src/SelfManage/Verify/FailedToVerifyRelease.php +++ b/src/SelfManage/Verify/FailedToVerifyRelease.php @@ -4,6 +4,7 @@ namespace Php\Pie\SelfManage\Verify; +use Composer\Downloader\TransportException; use Php\Pie\SelfManage\Update\ReleaseMetadata; use RuntimeException; use Symfony\Component\Process\Exception\ProcessFailedException; @@ -14,6 +15,18 @@ class FailedToVerifyRelease extends RuntimeException { + public static function fromGithubAuthenticationFailure(TransportException $transportException): self + { + return new self( + $transportException->getMessage() . ' while downloading attestation to verify PIE. This likely ' + . 'means you have not set up GitHub authentication in Composer yet. PIE relies on this Composer ' + . 'authentication configuration to make API requests to GitHub; check out ' + . 'https://getcomposer.org/doc/articles/authentication-for-private-packages.md#command-line-github-oauth' + . 'for help configuring Composer, or set GITHUB_TOKEN if the environment makes sense', + previous: $transportException, + ); + } + public static function fromAttestationException(FailedToVerifyArtifact $failedToVerifyArtifact): self { return new self($failedToVerifyArtifact->getMessage(), 0, $failedToVerifyArtifact); diff --git a/src/SelfManage/Verify/FallbackVerificationUsingOpenSsl.php b/src/SelfManage/Verify/FallbackVerificationUsingOpenSsl.php index fa643c18..bdbcda48 100644 --- a/src/SelfManage/Verify/FallbackVerificationUsingOpenSsl.php +++ b/src/SelfManage/Verify/FallbackVerificationUsingOpenSsl.php @@ -4,6 +4,7 @@ namespace Php\Pie\SelfManage\Verify; +use Composer\Downloader\TransportException; use Composer\IO\IOInterface; use Php\Pie\File\BinaryFile; use Php\Pie\SelfManage\Update\FetchPieRelease; @@ -73,6 +74,12 @@ public function verify(ReleaseMetadata $releaseMetadata, BinaryFile $pharFilenam ); } catch (FailedToVerifyArtifact $failedToVerifyArtifact) { throw FailedToVerifyRelease::fromAttestationException($failedToVerifyArtifact); + } catch (TransportException $transportException) { + if ($transportException->getStatusCode() === 401) { + throw FailedToVerifyRelease::fromGithubAuthenticationFailure($transportException); + } + + throw $transportException; } $io->write(sprintf(