Commit d135631f by Qiang Xue

Avoid logging db errors repeatedly.

parent af6f6d15
...@@ -146,9 +146,9 @@ class Command extends \yii\base\Component ...@@ -146,9 +146,9 @@ class Command extends \yii\base\Component
try { try {
$this->pdoStatement = $this->db->pdo->prepare($sql); $this->pdoStatement = $this->db->pdo->prepare($sql);
} catch (\Exception $e) { } catch (\Exception $e) {
Yii::error($e->getMessage() . "\nFailed to prepare SQL: $sql", __METHOD__); $message = $e->getMessage() . "\nFailed to prepare SQL: $sql";
$errorInfo = $e instanceof \PDOException ? $e->errorInfo : null; $errorInfo = $e instanceof \PDOException ? $e->errorInfo : null;
throw new Exception($e->getMessage(), $errorInfo, (int)$e->getCode(), $e); throw new Exception($message, $errorInfo, (int)$e->getCode(), $e);
} }
} }
} }
...@@ -293,10 +293,7 @@ class Command extends \yii\base\Component ...@@ -293,10 +293,7 @@ class Command extends \yii\base\Component
return $n; return $n;
} catch (\Exception $e) { } catch (\Exception $e) {
Yii::endProfile($token, __METHOD__); Yii::endProfile($token, __METHOD__);
$message = $e->getMessage(); $message = $e->getMessage() . "\nThe SQL being executed was: $rawSql";
Yii::error("$message\nFailed to execute SQL: $rawSql", __METHOD__);
$errorInfo = $e instanceof \PDOException ? $e->errorInfo : null; $errorInfo = $e instanceof \PDOException ? $e->errorInfo : null;
throw new Exception($message, $errorInfo, (int)$e->getCode(), $e); throw new Exception($message, $errorInfo, (int)$e->getCode(), $e);
} }
...@@ -430,8 +427,7 @@ class Command extends \yii\base\Component ...@@ -430,8 +427,7 @@ class Command extends \yii\base\Component
return $result; return $result;
} catch (\Exception $e) { } catch (\Exception $e) {
Yii::endProfile($token, __METHOD__); Yii::endProfile($token, __METHOD__);
$message = $e->getMessage(); $message = $e->getMessage() . "\nThe SQL being executed was: $rawSql";
Yii::error("$message\nCommand::$method() failed: $rawSql", __METHOD__);
$errorInfo = $e instanceof \PDOException ? $e->errorInfo : null; $errorInfo = $e instanceof \PDOException ? $e->errorInfo : null;
throw new Exception($message, $errorInfo, (int)$e->getCode(), $e); throw new Exception($message, $errorInfo, (int)$e->getCode(), $e);
} }
......
...@@ -307,9 +307,7 @@ class Connection extends Component ...@@ -307,9 +307,7 @@ class Connection extends Component
Yii::endProfile($token, __METHOD__); Yii::endProfile($token, __METHOD__);
} catch (\PDOException $e) { } catch (\PDOException $e) {
Yii::endProfile($token, __METHOD__); Yii::endProfile($token, __METHOD__);
Yii::error("Failed to open DB connection ({$this->dsn}): " . $e->getMessage(), __METHOD__); throw new Exception($e->getMessage(), $e->errorInfo, (int)$e->getCode(), $e);
$message = YII_DEBUG ? 'Failed to open DB connection: ' . $e->getMessage() : 'Failed to open DB connection.';
throw new Exception($message, $e->errorInfo, (int)$e->getCode(), $e);
} }
} }
} }
......
...@@ -55,7 +55,7 @@ EOD; ...@@ -55,7 +55,7 @@ EOD;
foreach ($this->data['messages'] as $log) { foreach ($this->data['messages'] as $log) {
list ($message, $level, $category, $time, $traces) = $log; list ($message, $level, $category, $time, $traces) = $log;
$time = date('H:i:s.', $time) . sprintf('%03d', (int)(($time - (int)$time) * 1000)); $time = date('H:i:s.', $time) . sprintf('%03d', (int)(($time - (int)$time) * 1000));
$message = Html::encode($message); $message = nl2br(Html::encode($message));
if (!empty($traces)) { if (!empty($traces)) {
$message .= Html::ul($traces, array( $message .= Html::ul($traces, array(
'class' => 'trace', 'class' => 'trace',
......
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