function migrate_decode_exception in Migrate 6.2
Decode an exception, especially to retrieve the correct caller.
Parameters
$exception: The exception object that was thrown.
Return value
An error in the format expected by _drupal_log_error().
1 call to migrate_decode_exception()
- MigrationBase::handleException in includes/
base.inc - Takes an Exception object and both saves and displays it, pulling additional information on the location triggering the exception.
File
- includes/
d7.inc, line 57 - Drupal 7 functions 'n' things implemented in Drupal 6, to ease backporting
Code
function migrate_decode_exception($exception) {
$message = $exception
->getMessage();
$backtrace = $exception
->getTrace();
// Add the line throwing the exception to the backtrace.
array_unshift($backtrace, array(
'line' => $exception
->getLine(),
'file' => $exception
->getFile(),
));
// For PDOException errors, we try to return the initial caller,
// skipping internal functions of the database layer.
if (is_a($exception, 'PDOException')) {
// The first element in the stack is the call, the second element gives us the caller.
// We skip calls that occurred in one of the classes of the database layer
// or in one of its global functions.
// $db_functions = array('db_query', 'pager_query', 'db_query_range', 'db_query_temporary', 'update_sql');
$db_functions = array(
'db_query',
'_db_query',
'pager_query',
'db_query_range',
'db_query_temporary',
'update_sql',
);
while (!empty($backtrace[1]) && ($caller = $backtrace[1]) && (isset($caller['class']) && (strpos($caller['class'], 'Query') !== FALSE || strpos($caller['class'], 'Database') !== FALSE || strpos($caller['class'], 'PDO') !== FALSE) || in_array($caller['function'], $db_functions))) {
// We remove that call.
array_shift($backtrace);
}
if (isset($exception->query_string, $exception->args)) {
$message .= ": " . $exception->query_string . "; " . print_r($exception->args, TRUE);
}
}
$caller = migrate_get_last_caller($backtrace);
return array(
'%type' => get_class($exception),
'%message' => $message,
'%function' => $caller['function'],
'%file' => $caller['file'],
'%line' => $caller['line'],
);
}