Skip to content

Commit 63c7c89

Browse files
committed
Added error handling for asset-package/update and update-list
1 parent c9bd8a4 commit 63c7c89

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/console/AssetPackageController.php

+20-1
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,47 @@
1919

2020
class AssetPackageController extends \yii\console\Controller
2121
{
22+
/**
23+
* @param string $type the package type. Can be either `bower` or `npm`
24+
* @param string $name the package name
25+
* @return boolean Whether the update was successful
26+
*/
2227
public function actionUpdate($type, $name)
2328
{
2429
try {
2530
$package = new AssetPackage($type, $name);
2631
$package->update();
2732
echo 'updated ' . $package->getHash() . ' ' . $package->getFullName() . "\n";
33+
return true;
2834
} catch (\Exception $e) {
2935
echo Console::renderColoredString("%Rfailed%N $type/$name:%n {$e->getMessage()}\n");
36+
return false;
3037
}
3138
}
3239

3340
public function actionUpdateList($file = STDIN)
3441
{
3542
$handler = is_resource($file) ? $file : fopen($file, 'r');
43+
44+
$errorPackages = [];
45+
3646
while ($line = fgets($handler)) {
3747
list($full) = preg_split('/\s+/', trim($line));
3848
list($type, $name) = AssetPackage::splitFullName($full);
39-
$this->actionUpdate($type, $name);
49+
if (!$this->actionUpdate($type, $name)) {
50+
$errorPackages[] = $full;
51+
}
4052
}
53+
4154
if (!is_resource($file)) {
4255
fclose($handler);
4356
}
57+
58+
if (!empty($errorPackages)) {
59+
echo Console::renderColoredString("%RThe following packages were not updated due to unrecoverable errors:%n\n");
60+
echo implode("\n", $errorPackages);
61+
}
62+
echo "\n";
4463
}
4564

4665
public function actionUpdateAll()

0 commit comments

Comments
 (0)