Browse Source

Fixes #5954: `yii message` command now shows user friendly error if it's not able to parse source file

tags/2.0.1
Alexander Makarov 10 years ago
parent
commit
4b97abacc7
  1. 1
      framework/CHANGELOG.md
  2. 14
      framework/console/controllers/MessageController.php

1
framework/CHANGELOG.md

@ -31,6 +31,7 @@ Yii Framework 2 Change Log
- Enh #5735: Added `yii\bootstrap\Tabs::renderTabContent` to support manually rendering tab contents (RomeroMsk)
- Enh #5770: Added more PHP error names for `ErrorException` (mongosoft)
- Enh #5806: Allow `Html::encode()` to be used when the application is not started (qiangxue)
- Enh #5954: `yii message` command now shows user friendly error if it's not able to parse source file (samdark)
- Enh: `Console::confirm()` now uses `Console::stdout()` instead of `echo` to be consistent with all other functions (cebe)
- Enh: `yii\rbac\DbManager` migration now uses database component specified in component settings instead of always using default `db` (samdark)
- Chg #3630: `yii\db\Command::queryInternal()` is now protected (samdark)

14
framework/console/controllers/MessageController.php

@ -8,8 +8,10 @@
namespace yii\console\controllers;
use Yii;
use yii\base\ErrorException;
use yii\console\Controller;
use yii\console\Exception;
use yii\helpers\Console;
use yii\helpers\FileHelper;
use yii\helpers\VarDumper;
use yii\i18n\GettextPoFile;
@ -258,7 +260,17 @@ class MessageController extends Controller
for ($i = 0; $i < $n; ++$i) {
$category = substr($matches[$i][1], 1, -1);
$message = $matches[$i][2];
$messages[$category][] = eval("return {$message};"); // use eval to eliminate quote escape
try {
$messages[$category][] = eval("return {$message};"); // use eval to eliminate quote escape
} catch (ErrorException $e) {
$category = Console::ansiFormat($category, [Console::FG_CYAN]);
$message = Console::ansiFormat($message, [Console::FG_CYAN]);
$fileName = Console::ansiFormat($fileName, [Console::FG_CYAN]);
$error = Console::ansiFormat($e->getMessage(), [Console::FG_RED]);
$this->stdout("Failed parsing $fileName, $message in $category category:\n" . $error . "\n");
Yii::$app->end(self::EXIT_CODE_ERROR);
}
}
}

Loading…
Cancel
Save