Skip to content

Commit a2999a4

Browse files
authored
Merge pull request #668 from asgrim/585-improve-error-message-when-no-gh-token
585: improve messaging when no auth available during verify
2 parents eadea47 + f78bc2d commit a2999a4

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

src/SelfManage/Verify/FailedToVerifyRelease.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Php\Pie\SelfManage\Verify;
66

7+
use Composer\Downloader\TransportException;
78
use Php\Pie\SelfManage\Update\ReleaseMetadata;
89
use RuntimeException;
910
use Symfony\Component\Process\Exception\ProcessFailedException;
@@ -14,6 +15,18 @@
1415

1516
class FailedToVerifyRelease extends RuntimeException
1617
{
18+
public static function fromGithubAuthenticationFailure(TransportException $transportException): self
19+
{
20+
return new self(
21+
$transportException->getMessage() . ' while downloading attestation to verify PIE. This likely '
22+
. 'means you have not set up GitHub authentication in Composer yet. PIE relies on this Composer '
23+
. 'authentication configuration to make API requests to GitHub; check out '
24+
. 'https://getcomposer.org/doc/articles/authentication-for-private-packages.md#command-line-github-oauth'
25+
. 'for help configuring Composer, or set GITHUB_TOKEN if the environment makes sense',
26+
previous: $transportException,
27+
);
28+
}
29+
1730
public static function fromAttestationException(FailedToVerifyArtifact $failedToVerifyArtifact): self
1831
{
1932
return new self($failedToVerifyArtifact->getMessage(), 0, $failedToVerifyArtifact);

src/SelfManage/Verify/FallbackVerificationUsingOpenSsl.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Php\Pie\SelfManage\Verify;
66

7+
use Composer\Downloader\TransportException;
78
use Composer\IO\IOInterface;
89
use Php\Pie\File\BinaryFile;
910
use Php\Pie\SelfManage\Update\FetchPieRelease;
@@ -73,6 +74,12 @@ public function verify(ReleaseMetadata $releaseMetadata, BinaryFile $pharFilenam
7374
);
7475
} catch (FailedToVerifyArtifact $failedToVerifyArtifact) {
7576
throw FailedToVerifyRelease::fromAttestationException($failedToVerifyArtifact);
77+
} catch (TransportException $transportException) {
78+
if ($transportException->getStatusCode() === 401) {
79+
throw FailedToVerifyRelease::fromGithubAuthenticationFailure($transportException);
80+
}
81+
82+
throw $transportException;
7683
}
7784

7885
$io->write(sprintf(

0 commit comments

Comments
 (0)