Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Error handling following DB Package upgrade #16213

Merged
merged 1 commit into from
Jan 6, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions CRM/Core/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -803,16 +803,19 @@ public static function formatHtmlException(Exception $e) {
if ($e instanceof PEAR_Exception) {
$ei = $e;
while (is_callable([$ei, 'getCause'])) {
if ($ei->getCause() instanceof PEAR_Error) {
$msg .= '<table class="crm-db-error">';
$msg .= sprintf('<thead><tr><th>%s</th><th>%s</th></tr></thead>', ts('Error Field'), ts('Error Value'));
$msg .= '<tbody>';
foreach (['Type', 'Code', 'Message', 'Mode', 'UserInfo', 'DebugInfo'] as $f) {
$msg .= sprintf('<tr><td>%s</td><td>%s</td></tr>', $f, call_user_func([$ei->getCause(), "get$f"]));
// DB_ERROR doesn't have a getCause but does have a __call function which tricks is_callable.
if (!$ei instanceof DB_Error) {
if ($ei->getCause() instanceof PEAR_Error) {
$msg .= '<table class="crm-db-error">';
$msg .= sprintf('<thead><tr><th>%s</th><th>%s</th></tr></thead>', ts('Error Field'), ts('Error Value'));
$msg .= '<tbody>';
foreach (['Type', 'Code', 'Message', 'Mode', 'UserInfo', 'DebugInfo'] as $f) {
$msg .= sprintf('<tr><td>%s</td><td>%s</td></tr>', $f, call_user_func([$ei->getCause(), "get$f"]));
}
$msg .= '</tbody></table>';
}
$msg .= '</tbody></table>';
$ei = $ei->getCause();
}
$ei = $ei->getCause();
}
$msg .= $e->toHtml();
}
Expand All @@ -835,12 +838,19 @@ public static function formatTextException(Exception $e) {

$ei = $e;
while (is_callable([$ei, 'getCause'])) {
if ($ei->getCause() instanceof PEAR_Error) {
foreach (['Type', 'Code', 'Message', 'Mode', 'UserInfo', 'DebugInfo'] as $f) {
$msg .= sprintf(" * ERROR %s: %s\n", strtoupper($f), call_user_func([$ei->getCause(), "get$f"]));
// DB_ERROR doesn't have a getCause but does have a __call function which tricks is_callable.
if (!$ei instanceof DB_Error) {
if ($ei->getCause() instanceof PEAR_Error) {
foreach (['Type', 'Code', 'Message', 'Mode', 'UserInfo', 'DebugInfo'] as $f) {
$msg .= sprintf(" * ERROR %s: %s\n", strtoupper($f), call_user_func([$ei->getCause(), "get$f"]));
}
}
$ei = $ei->getCause();
}
// if we have reached a DB_Error assume that is the end of the road.
else {
$ei = NULL;
}
$ei = $ei->getCause();
}
$msg .= self::formatBacktrace($e->getTrace());
return $msg;
Expand Down