Skip to content

Commit

Permalink
LastModifiedFetcher: suggest new process runtime error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ogizanagi committed Apr 4, 2024
1 parent 6938a01 commit 887f6d1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/Service/Git/LastModifiedFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Exception\RuntimeException;
use Symfony\Component\Process\Process;
use Symfony\Contracts\Service\ResetInterface;

Expand Down Expand Up @@ -49,11 +50,13 @@ public function __invoke(string $filePath): ?\DateTimeImmutable

try {
$process->run();
} catch (ProcessFailedException $exception) {
} catch (RuntimeException $e) {
self::$gitAvailable = false;

$this->logger->warning('Git was not found at path "{gitPath}". Check the binary path is correct or part of your PATH.', [
$this->logger->warning('An unexpected error occurred while trying to check the git binary at path "{gitPath}"', [
'gitPath' => $this->gitPath,
'exception' => $e,
'exception_message' => $e->getMessage(),
]);

return null;
Expand Down
5 changes: 4 additions & 1 deletion tests/Unit/Service/Git/LastModifiedFetcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ public function testUnavailable(): void
$fetcher->reset();

self::assertNull($fetcher->__invoke('some-fake-path'));
self::assertTrue($logger->hasWarningThatContains('Git was not found at path'));
self::assertTrue(
$logger->hasWarningThatContains('Git was not found at path')
|| $logger->hasWarningThatContains('An unexpected error occurred while trying to check the git binary at path')
);
self::assertCount(1, $logger->records);

self::assertNull($fetcher->__invoke('some-fake-path'));
Expand Down

0 comments on commit 887f6d1

Please sign in to comment.