Skip to content

Commit

Permalink
display copying errors in the CLI (#127)
Browse files Browse the repository at this point in the history
* display copying errors in the CLI

* fix style

* Update CopyRequestFailedException.php

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
themsaid and taylorotwell authored May 24, 2021
1 parent accb920 commit f807c52
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/Aws/AwsStorageProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
namespace Laravel\VaporCli\Aws;

use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Pool;
use GuzzleHttp\Psr7\Request;
use Laravel\VaporCli\ConsoleVaporClient;
use Laravel\VaporCli\Exceptions\CopyRequestFailedException;
use Laravel\VaporCli\Helpers;
use Symfony\Component\Console\Helper\ProgressBar;

Expand Down Expand Up @@ -108,7 +110,12 @@ public function executeCopyRequests($requests)
}
};

(new Pool(new Client(), $requests(), ['concurrency' => 10]))
(new Pool(new Client(), $requests(), [
'concurrency' => 10,
'rejected' => function (RequestException $reason, $index) {
throw new CopyRequestFailedException($reason->getMessage(), $index);
},
]))
->promise()
->wait();
}
Expand Down
38 changes: 38 additions & 0 deletions src/Exceptions/CopyRequestFailedException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Laravel\VaporCli\Exceptions;

use RuntimeException;

class CopyRequestFailedException extends RuntimeException
{
/**
* The file index.
*
* @var int
*/
public $index;

/**
* Create a new exception instance.
*
* @param string $message
* @param int $index
*/
public function __construct($message = '', $index = 0)
{
parent::__construct($message);

$this->index = $index;
}

/**
* Get the file index.
*
* @return int
*/
public function getIndex()
{
return $this->index;
}
}
12 changes: 11 additions & 1 deletion src/ServeAssets.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Laravel\VaporCli;

use Laravel\VaporCli\Aws\AwsStorageProvider;
use Laravel\VaporCli\Exceptions\CopyRequestFailedException;

class ServeAssets
{
Expand Down Expand Up @@ -75,7 +76,16 @@ protected function executeCopyAssetRequests($requests, $assetPath)
}

if (! empty($requests)) {
$storage->executeCopyRequests($requests);
try {
$storage->executeCopyRequests($requests);
} catch (CopyRequestFailedException $e) {
$request = $requests[$e->getIndex()];

Helpers::line("<fg=red>Copying:</> {$request['path']}");
Helpers::write($e->getMessage());

exit(1);
}
}
}

Expand Down

0 comments on commit f807c52

Please sign in to comment.