Commit 4b97abac by Alexander Makarov

Fixes #5954: `yii message` command now shows user friendly error if it's not…

Fixes #5954: `yii message` command now shows user friendly error if it's not able to parse source file
parent b8cb5e2a
......@@ -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)
......
......@@ -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);
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment