Normalized exception stacktrace.

@param \Throwable $e
@return array
7212
protected function getStacktrace(\Throwable $e): array
    {
        $stacktrace = $e->getTrace();
        if (empty($stacktrace)) {
            return [];
        }

        //Let's let's clarify exception location
        $header = [
                'file' => $e->getFile(),
                'line' => $e->getLine()
            ] + $stacktrace[0];

        if ($stacktrace[0] != $header) {
            array_unshift($stacktrace, $header);
        }

        return $stacktrace;
    }
772740
private function convertException(Exception $e)
    {
        $data = [];
        $data['message']  = $e->getMessage();
        $data['code']     = $e->getCode();
        $data['trace']    = $this->filterTrace($e->getTrace());
        $data['status']   = Response::HTTP_INTERNAL_SERVER_ERROR;

        // determine the relevant file
        $firstTraceEntry = !empty($data['trace']) ? reset($data['trace']) : null;
        if ($firstTraceEntry !== null && isset($firstTraceEntry['file']) && isset($firstTraceEntry['line'])) {
            $data['file'] = $firstTraceEntry['file'];
            $data['line'] = $firstTraceEntry['line'];
        }
        else {
            $data['file'] = $e->getFile();
            $data['line'] = $e->getLine();
        }

        if ($e instanceof HttpException) {
            $data['status'] = $e->getStatusCode() ?: Response::HTTP_INTERNAL_SERVER_ERROR;
        }
        else if ($e instanceof QueryException) {
            $data['ansiCode']   = isset($e->errorInfo[0]) ? $e->errorInfo[0] : null;
            $data['driverCode'] = isset($e->errorInfo[1]) ? $e->errorInfo[1] : null;
            if (!empty($e->errorInfo[2])) {
                $data['message'] = $e->errorInfo[2];
            }
            $data['sql'] = $e->getDump();
        }

        return $data;
    }
896310
public static function fromException(\Exception $e)
    {
        if ($e instanceof XsollaWebhookException) {
            return static::fromErrorCode($e->getXsollaErrorCode(), $e->getMessage(), $e->getHttpStatusCode());
        } else {
            return static::fromErrorCode('FATAL_ERROR', $e->getMessage());
        }
    }
1019250
public function formatStackTrace( ezcDebugStacktraceIterator $stackTrace )
    {
        $res = array();
        foreach ( $stackTrace as $index => $element )
        {
            $function = ( isset( $element['class'] ) ? "{$element['class']}::" : '' )
            . $element['function'] . '('
            . implode( ', ', $element['params'] )
            . ')';
            $location = "{$element['file']}:{$element['line']}";
            $res[$index] = $function.' ('.$location.')';
        }
        return  $res;
    }
1215844
public static function buildExceptionStore(\Exception $e)
    {
        $exceptionStore = new ExceptionStore();
        $exceptionStore->setMessage($e->getMessage());
        $exceptionStore->setCode($e->getCode());
        $exceptionStore->setExceptionClass(get_class($e));
        $t = explode('\n', $e->getTraceAsString());
        $exceptionStore->setStack($t);

        $stack = $e->getTrace();
        if (count($stack) > 0) {
            //Setting default unknown values
            $exceptionStore->setFile("unknown");
            $exceptionStore->setLine(0);
            //Searching for a valid stackItem
            $stackItem = static::searchForFileAndLineCalledFromStack($stack);
            if (!is_null($stackItem)) {
                $exceptionStore->setFile(basename($stackItem['file'],'.php'));
                $exceptionStore->setLine($stackItem['line']);
            }
        }

        return $exceptionStore;
    }
348722
protected function normalizeException(\Exception $e)
    {
        $data = array(
            'class' => get_class($e),
            'message' => $e->getMessage(),
            'code' => $e->getCode(),
            'file' => $e->getFile().':'.$e->getLine(),
        );

        $trace = $e->getTrace();
        foreach ($trace as $frame) {
            if (isset($frame['file'])) {
                $data['trace'][] = $frame['file'].':'.$frame['line'];
            } else {
                // We should again normalize the frames, because it might contain invalid items
                $data['trace'][] = $this->toJson($this->normalize($frame, array()), true);
            }
        }

        if ($previous = $e->getPrevious()) {
            $data['previous'] = $this->normalizeException($previous);
        }

        return $this->toJson($data);
    }
1353735
static protected function exceptionToSlackAttach(E $e)
    {
        $fields = [ ];

        $addToField = function ($name, $value, $short = false) use (&$fields) {
            if ( ! empty( $value )) {
                $fields[] = [
                    "title" => $name,
                    "value" => $value,
                    "short" => $short
                ];
            }
        };

        $addToField("Exception", get_class($e), true);
        $addToField("Hash", ExceptionHelper::hash($e), true);
        $addToField("Http code", ExceptionHelper::statusCode($e), true);
        $addToField("Code", $e->getCode(), true);
        $addToField("File", $e->getFile(), true);
        $addToField("Line", $e->getLine(), true);
        $addToField("Request url", Request::url(), true);
        $addToField("Request method", Request::method(), true);
        $addToField("Request param", json_encode(Request::all()), true);

        return [
            "color"    => "danger",
            "title"    => $e->getMessage(),
            "fallback" => ! empty( $e->getMessage() ) ? $e->getMessage() : get_class($e),
            "fields"   => $fields,
            "text"     => $e->getTraceAsString()
        ];
    }
532998
protected function get_error_from_exception($e)
    {
        $data = array();

        if ($e instanceof Crypt_GPG_KeyNotFoundException) {
            $error = enigma_error::KEYNOTFOUND;
            $data['id'] = $e->getKeyId();
        }
        else if ($e instanceof Crypt_GPG_BadPassphraseException) {
            $error = enigma_error::BADPASS;
            $data['bad']     = $e->getBadPassphrases();
            $data['missing'] = $e->getMissingPassphrases();
        }
        else if ($e instanceof Crypt_GPG_NoDataException) {
            $error = enigma_error::NODATA;
        }
        else if ($e instanceof Crypt_GPG_DeletePrivateKeyException) {
            $error = enigma_error::DELKEY;
        }
        else {
            $error = enigma_error::INTERNAL;
        }

        $msg = $e->getMessage();

        return new enigma_error($error, $msg, $data);
    }
520400
public static function toStackTrace($ex)
    {
        $list = [];
        for ($stack = Throwable::getThrowableStack($ex); $stack !== null; $stack = $stack['prev'])
        {
            $list = array_merge($stack['trace'], $list);
        }

        return $list;
    }
1230389
protected function handleException(Exception $e)
    {
        // if ($e instanceof MethodNotAllowedException) {
        //     $handler = 'notAllowedHandler';
        //     $params = [$e->getRequest(), $e->getResponse(), $e->getAllowedMethods()];
        // } elseif ($e instanceof NotFoundException) {
        //     $handler = 'notFoundHandler';
        //     $params = [$e->getRequest(), $e->getResponse(), $e];
        // } elseif ($e instanceof SlimException) {
        //     // This is a Stop exception and contains the response
        //     return $e->getResponse();
        // } else {
            // Other exception, use $request and $response params
            $handler = 'errorHandler';
            $params = [$e];
        // }

        if ($this->getContainer()->has($handler)) {
            $callable = $this->getContainer()->get($handler);
            // Call the registered handler
            return call_user_func_array($callable, $params);
        }

        // No handlers found, so just display simple error
        $this->displayError($e->getMessage());
        exit($e->getCode() ?: 1);
    }
947582
protected function convertExceptionToArray(Exception $e)
    {
        return $this->container->make('config')->get('app.debug') ? [
            'message' => $e->getMessage(),
            'exception' => get_class($e),
            'file' => $e->getFile(),
            'line' => $e->getLine(),
            'trace' => collect($e->getTrace())->map(function ($trace) {
                return Arr::except($trace, ['args']);
            })->all(),
        ] : [
            'message' => $this->isServiceException($e) ? $e->getMessage() : 'Server Error',
        ];
    }
634859
public function onExceptionHandle(\Throwable $e)
    {
        try {
            if ($e->getPrevious()) {
                $ce = $e->getPrevious();
                $errMsg = dump($ce, false, true);
            } else {
                $errMsg = dump($e, false, true);
                $ce = $e;
            }

            $this->getContext()->getLog()->error($errMsg);
            $this->outputJson(parent::$stdClass, 'Internal Server Error', 500);
        } catch (\Throwable $ne) {
            getInstance()->log->error('previous exception ' . dump($ce, false, true));
            getInstance()->log->error('handle exception ' . dump($ne, false, true));
        }
    }
1151557
public static function getExceptionInfo(Throwable $t) : array
    {
        return [
            'type' => get_class($t),
            'message' => $t->getMessage(),
            'code' => $t->getCode(),
            'file' => $t->getFile(),
            'line' => $t->getLine(),
            'trace' => $t->getTraceAsString(),
        ];
    }
407601
public function exception($e)
    {
        $this->setParams(
            $e->getCode(),
            $e->getMessage(),
            $e->getFile(),
            $e->getLine(),
            $e->getTraceAsString());

        return $this->render();
    }
1283326
protected function _getException(\Throwable $e, $h1)
	{
		try
		{
			return $this->_getFormatterStrategy()->format($e, $h1);
		}
		catch (\Throwable $e2)
		{
			return "Error '" . get_class($e2) . "' during processing of exception '" . get_class($e) . "' with message '{$e2->getMessage()}'.";
		}
	}
551385
public function logServerError(Throwable $e)
    {
        if ($this->isInTesting()) {
            return;
        }

        $exception = $this->normalizeException($e);
        $this->container->make(ConsoleOutput::class)
            ->writeln(sprintf("<error>%s</error>", $exception));

        $this->container->make(ExceptionHandler::class)
            ->report($exception);
    }
1071821
private function cleanExceptions(Exception $exception)
    {
        $exceptions = [];

        do {
            $exceptions[] = [
                'class'         => get_class($exception),
                'exception'     => new ObjectStub($exception),
                'message'       => $exception->getMessage(),
                'code'          => $exception->getCode(),
                'file'          => $exception->getFile(),
                'line'          => $exception->getLine(),
                'traceAsString' => $exception->getTraceAsString(),
                'trace'         => new SerializableValueStub($exception->getTrace()),
            ];
        } while ($exception = $exception->getPrevious());

        return $exceptions;
    }