Browse Source

Avoid logging db errors repeatedly.

tags/2.0.0-beta
Qiang Xue 11 years ago
parent
commit
d135631f8e
  1. 12
      framework/yii/db/Command.php
  2. 4
      framework/yii/db/Connection.php
  3. 2
      framework/yii/debug/panels/LogPanel.php

12
framework/yii/db/Command.php

@ -146,9 +146,9 @@ class Command extends \yii\base\Component
try {
$this->pdoStatement = $this->db->pdo->prepare($sql);
} 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;
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
return $n;
} catch (\Exception $e) {
Yii::endProfile($token, __METHOD__);
$message = $e->getMessage();
Yii::error("$message\nFailed to execute SQL: $rawSql", __METHOD__);
$message = $e->getMessage() . "\nThe SQL being executed was: $rawSql";
$errorInfo = $e instanceof \PDOException ? $e->errorInfo : null;
throw new Exception($message, $errorInfo, (int)$e->getCode(), $e);
}
@ -430,8 +427,7 @@ class Command extends \yii\base\Component
return $result;
} catch (\Exception $e) {
Yii::endProfile($token, __METHOD__);
$message = $e->getMessage();
Yii::error("$message\nCommand::$method() failed: $rawSql", __METHOD__);
$message = $e->getMessage() . "\nThe SQL being executed was: $rawSql";
$errorInfo = $e instanceof \PDOException ? $e->errorInfo : null;
throw new Exception($message, $errorInfo, (int)$e->getCode(), $e);
}

4
framework/yii/db/Connection.php

@ -307,9 +307,7 @@ class Connection extends Component
Yii::endProfile($token, __METHOD__);
} catch (\PDOException $e) {
Yii::endProfile($token, __METHOD__);
Yii::error("Failed to open DB connection ({$this->dsn}): " . $e->getMessage(), __METHOD__);
$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);
throw new Exception($e->getMessage(), $e->errorInfo, (int)$e->getCode(), $e);
}
}
}

2
framework/yii/debug/panels/LogPanel.php

@ -55,7 +55,7 @@ EOD;
foreach ($this->data['messages'] as $log) {
list ($message, $level, $category, $time, $traces) = $log;
$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)) {
$message .= Html::ul($traces, array(
'class' => 'trace',

Loading…
Cancel
Save