/** * Returns an Inspector for a previous Exception, if any. * @todo Clean this up a bit, cache stuff a bit better. * @return Inspector */ public function getPreviousExceptionInspector() { if ($this->previousExceptionInspector === null) { $previousException = $this->exception->getPrevious(); if ($previousException) { $this->previousExceptionInspector = new Inspector($previousException); } } return $this->previousExceptionInspector; }
/** * Send exception message to client * @param \Exception $exception */ public function dispatchException(\Throwable $exception) { if ($this->isActive()) { if ($this->dispatchPreviousExceptions && $exception->getPrevious()) { $this->dispatchException($exception->getPrevious()); } $message = new \PhpConsole\ErrorMessage(); $message->code = $exception->getCode(); $message->class = get_class($exception); $message->data = $this->dumper->dump($exception->getMessage()); $message->file = $exception->getFile(); $message->line = $exception->getLine(); $message->trace = self::fetchTrace($exception->getTrace(), $message->file, $message->line); $this->sendMessage($message); } }
/** * @param \Exception|\Throwable $exception */ public function handle_exception($exception) { if (getenv('APP_ENV') === 'dev') { list($code, $file, $line, $message, $previous, $trace, $trace_string) = [$exception->getCode(), $exception->getFile(), $exception->getLine(), $exception->getMessage(), $exception->getPrevious(), $exception->getTrace(), $exception->getTraceAsString()]; $trace_info = "<b>file</b>: {$trace[0]['file']} <b>in line</b> ({$trace[0]['line']})"; echo "<h2>COGS Runtime Exception: [::{$code}] {$message}</h2>"; echo "<b>Trace:</b><br>"; echo "<pre>{$trace_string}</pre>"; echo "<b>Debug:</b><br>"; dump(compact('code', 'file', 'line', 'message', 'previous', 'trace')); } }
/** * @param Throwable $exception */ public function handle(\Throwable $exception) { if ($exception instanceof HttpException) { http_response_code($exception->getStatusCode()); } if (false === $this->debug) { return; } if (null !== $exception->getPrevious()) { $exception = $exception->getPrevious(); } $message = $exception->getMessage(); $trace = $exception->getTrace(); array_unshift($trace, array('function' => '', 'file' => $exception->getFile() != null ? $exception->getFile() : null, 'line' => $exception->getLine() != null ? $exception->getLine() : null, 'args' => array())); $firstTrace = array_shift($trace); $firstTrace['excerpt'] = $this->excerpt($firstTrace['file'], $firstTrace['line']); array_unshift($trace, $firstTrace); echo $this->templateEngine->render(__DIR__ . '/templates/exception.php', array('message' => $message, 'trace' => $trace)); }
/** * @deprecated * @internal * @param \Exception|\Throwable $e * @param string $query * @param array $params * @return DBALException */ public function resolveException($e, $query = NULL, $params = []) { if ($this->throwOldKdybyExceptions !== TRUE) { return $e; } if ($e instanceof Doctrine\DBAL\DBALException && ($pe = $e->getPrevious()) instanceof \PDOException) { $info = $pe->errorInfo; } elseif ($e instanceof \PDOException) { $info = $e->errorInfo; } else { return new DBALException($e, $query, $params, $this); } if ($this->getDriver() instanceof Doctrine\DBAL\Driver\PDOMySql\Driver) { if ($info[0] == 23000 && $info[1] == self::MYSQL_ERR_UNIQUE) { // unique fail $columns = []; try { if (preg_match('~Duplicate entry .*? for key \'([^\']+)\'~', $info[2], $m) && ($table = self::resolveExceptionTable($e)) && ($indexes = $this->getSchemaManager()->listTableIndexes($table)) && isset($indexes[$m[1]])) { $columns[$m[1]] = $indexes[$m[1]]->getColumns(); } } catch (\Exception $e) { } return new DuplicateEntryException($e, $columns, $query, $params, $this); } elseif ($info[0] == 23000 && $info[1] == self::MYSQL_ERR_NOT_NULL) { // notnull fail $column = NULL; if (preg_match('~Column \'([^\']+)\'~', $info[2], $m)) { $column = $m[1]; } return new EmptyValueException($e, $column, $query, $params, $this); } } $raw = $e; do { $raw = $raw->getPrevious(); } while ($raw && !$raw instanceof \PDOException); return new DBALException($e, $query, $params, $this, $raw ? $raw->getMessage() : $e->getMessage()); }
/** * Convert an Exception or Error into an array (for logging) * * @param \Throwable $ex * @return array */ function throwableToArray(\Throwable $ex) : array { $prev = $ex->getPrevious(); return ['line' => $ex->getLine(), 'file' => $ex->getFile(), 'message' => $ex->getMessage(), 'code' => $ex->getCode(), 'trace' => $ex->getTrace(), 'previous' => $prev ? throwableToArray($prev) : null]; }
protected function normalizeException(\Throwable $e, int $depth = 0) : string { $previousText = ''; if ($previous = $e->getPrevious()) { do { $previousText .= ', ' . get_class($previous) . '(code: ' . $previous->getCode() . '): ' . $previous->getMessage() . ' at ' . $previous->getFile() . ':' . $previous->getLine(); } while ($previous = $previous->getPrevious()); } $str = '[object] (' . get_class($e) . '(code: ' . $e->getCode() . '): ' . $e->getMessage() . ' at ' . $e->getFile() . ':' . $e->getLine() . $previousText . ')'; if ($this->includeStacktraces) { $str .= "\n[stacktrace]\n" . $e->getTraceAsString() . "\n"; } return $str; }
/** * Echoes previous exceptions if applicable * * @author Art <*****@*****.**> * * @param null|\Throwable $e The previous exception * @param int $level How many previous exceptions have been echoed so far * * @codeCoverageIgnore */ protected function echoPreviousExceptions($e, $level = 0) { if ($level < $this->config->prevExceptionDepth && $e) { if ($this->isCLI) { $this->console->write('<eb>Preceded by </>')->write('<e>[' . $e->getCode() . '] ' . $e->getMessage() . '</>')->write('<e> @ ' . $e->getFile() . '\'s line ' . $e->getLine() . '</>', true)->writeln(''); } else { ?> <div> <span class="alo-bold">Preceded by </span> <span>[<?php echo $e->getCode(); ?> ]: <?php echo $e->getMessage(); ?> </span> <span> @ </span> <span class="alo-uline"><?php echo $e->getFile(); ?> </span> <span> @ line </span> <span class="alo-uline"><?php echo $e->getLine(); ?> </div> <?php } $this->echoPreviousExceptions($e->getPrevious(), ++$level); } }