From d216dc24f3548090f89b6d7a793ac4848902e47c Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Mon, 6 Jan 2020 07:44:35 +1100 Subject: [PATCH] Fix Error handling following DB Package upgrade --- CRM/Core/Error.php | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/CRM/Core/Error.php b/CRM/Core/Error.php index d99104c20273..1f0b4d40dbf2 100644 --- a/CRM/Core/Error.php +++ b/CRM/Core/Error.php @@ -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 .= ''; - $msg .= sprintf('', ts('Error Field'), ts('Error Value')); - $msg .= ''; - foreach (['Type', 'Code', 'Message', 'Mode', 'UserInfo', 'DebugInfo'] as $f) { - $msg .= sprintf('', $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 .= '
%s%s
%s%s
'; + $msg .= sprintf('', ts('Error Field'), ts('Error Value')); + $msg .= ''; + foreach (['Type', 'Code', 'Message', 'Mode', 'UserInfo', 'DebugInfo'] as $f) { + $msg .= sprintf('', $f, call_user_func([$ei->getCause(), "get$f"])); + } + $msg .= '
%s%s
%s%s
'; } - $msg .= ''; + $ei = $ei->getCause(); } - $ei = $ei->getCause(); } $msg .= $e->toHtml(); } @@ -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;