Skip to content

Commit f807c52

Browse files
display copying errors in the CLI (#127)
* display copying errors in the CLI * fix style * Update CopyRequestFailedException.php Co-authored-by: Taylor Otwell <[email protected]>
1 parent accb920 commit f807c52

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

src/Aws/AwsStorageProvider.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
namespace Laravel\VaporCli\Aws;
44

55
use GuzzleHttp\Client;
6+
use GuzzleHttp\Exception\RequestException;
67
use GuzzleHttp\Pool;
78
use GuzzleHttp\Psr7\Request;
89
use Laravel\VaporCli\ConsoleVaporClient;
10+
use Laravel\VaporCli\Exceptions\CopyRequestFailedException;
911
use Laravel\VaporCli\Helpers;
1012
use Symfony\Component\Console\Helper\ProgressBar;
1113

@@ -108,7 +110,12 @@ public function executeCopyRequests($requests)
108110
}
109111
};
110112

111-
(new Pool(new Client(), $requests(), ['concurrency' => 10]))
113+
(new Pool(new Client(), $requests(), [
114+
'concurrency' => 10,
115+
'rejected' => function (RequestException $reason, $index) {
116+
throw new CopyRequestFailedException($reason->getMessage(), $index);
117+
},
118+
]))
112119
->promise()
113120
->wait();
114121
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Laravel\VaporCli\Exceptions;
4+
5+
use RuntimeException;
6+
7+
class CopyRequestFailedException extends RuntimeException
8+
{
9+
/**
10+
* The file index.
11+
*
12+
* @var int
13+
*/
14+
public $index;
15+
16+
/**
17+
* Create a new exception instance.
18+
*
19+
* @param string $message
20+
* @param int $index
21+
*/
22+
public function __construct($message = '', $index = 0)
23+
{
24+
parent::__construct($message);
25+
26+
$this->index = $index;
27+
}
28+
29+
/**
30+
* Get the file index.
31+
*
32+
* @return int
33+
*/
34+
public function getIndex()
35+
{
36+
return $this->index;
37+
}
38+
}

src/ServeAssets.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Laravel\VaporCli;
44

55
use Laravel\VaporCli\Aws\AwsStorageProvider;
6+
use Laravel\VaporCli\Exceptions\CopyRequestFailedException;
67

78
class ServeAssets
89
{
@@ -75,7 +76,16 @@ protected function executeCopyAssetRequests($requests, $assetPath)
7576
}
7677

7778
if (! empty($requests)) {
78-
$storage->executeCopyRequests($requests);
79+
try {
80+
$storage->executeCopyRequests($requests);
81+
} catch (CopyRequestFailedException $e) {
82+
$request = $requests[$e->getIndex()];
83+
84+
Helpers::line("<fg=red>Copying:</> {$request['path']}");
85+
Helpers::write($e->getMessage());
86+
87+
exit(1);
88+
}
7989
}
8090
}
8191

0 commit comments

Comments
 (0)