Converts a throwable to html.

@param \Throwable $throwable The throwable.

@return string The html.
427360
private function throwableToHtml(\Throwable $throwable): string
    {
        if (!$this->isDebug) {
            return '';
        }

        return
            "<!DOCTYPE html>\n" .
            "<html lang=\"en\">\n" .
            "   <head>\n" .
            "      <meta charset=\"utf-8\">\n" .
            '      <title>' . htmlentities($throwable->getMessage()) . "</title>\n" .
            "      <style>\n" .
            "         html, body, h1, p, code, pre {margin:0; padding:0; font-size:16px; font-family:Arial, Helvetica, sans-serif; color:#555;}\n" .
            "         h1 {font-size:2em; margin:.5em; color:#338;}\n" .
            "         p, pre {font-size:1em; margin:1em;}\n" .
            "         pre, code {font-family:monospace; color:#000;}\n" .
            "      </style>\n" .
            "   </head>\n" .
            "   <body>\n" .
            '      <h1>' . htmlentities($throwable->getMessage()) . "</h1>\n" .
            "      <p>\n" .
            '         <code>' . htmlentities(get_class($throwable)) . '</code> was thrown from <code>' . htmlentities($throwable->getFile()) . ':' . htmlentities(strval($throwable->getLine())) . '</code> with message <code>' . htmlentities($throwable->getMessage()) . ' (' . htmlentities(strval($throwable->getCode())) . ")</code>\n" .
            "      </p>\n" .
            '      <pre>' . htmlentities($throwable->getTraceAsString()) . "</pre>\n" .
            "   </body>\n" .
            "</html>\n";
    }
556661
public function exception(\Throwable $throwable)
    {
        try {
            if (@Application::getSettings()->logging->exceptions) {
                $this->error('[EXCEPTION] ' . $throwable . PHP_EOL . $throwable->getTraceAsString());
            }
        } catch (SettingsException $throwable) {
            // No setting present, throwable will not be logged.
        }
    }
108656
public function log(\Throwable $throwable)
    {
        $logData  = date('Y-m-d H:i:s');
        $logData .= $this->fieldsOf($throwable);
        $logData .= $this->fieldsOf($throwable->getPrevious());
        error_log(
                $logData . "\n",
                3,
                $this->logDir() . DIRECTORY_SEPARATOR . 'exceptions-' . date('Y-m-d') . '.log'
        );
    }
172122
public function render($value): Htmlable
    {
        $attributes = '';
        foreach ($this->attributes as $key => $val) {
            $attributes .= " {$key}=\"{$val}\"";
        }

        $classes = implode(' ', $this->classes);
        return new HtmlString(
            "<div class=\"input-group {$classes}\"{$attributes}>" .
            ($this->position === self::POSITION_BEFORE ? $this->renderAdditional() : '') .
            $this->control->render($value)->toHtml() .
            ($this->position === self::POSITION_AFTER ? $this->renderAdditional() : '') .
            '</div>'
        );
    }
1019001
public function createResponse(Throwable $throwable, ContainerInterface $container): ThrowableResponseInterface
    {
        unset($container);

        $message            = 'Internal Server Error';
        $isJsonApiException = $throwable instanceof JsonApiException;

        $this->logError($throwable, $message);

        // if exception converter is specified it will be used to convert throwable to JsonApiException
        if ($isJsonApiException === false && $this->throwableConverter !== null) {
            try {
                /** @var ConverterInterface $converterClass */
                $converterClass = $this->throwableConverter;
                if (($converted = $converterClass::convert($throwable)) !== null) {
                    assert($converted instanceof JsonApiException);
                    $throwable          = $converted;
                    $isJsonApiException = true;
                }
            } catch (Throwable $ignored) {
            }
        }

        // compose JSON API Error with appropriate level of details
        if ($isJsonApiException === true) {
            /** @var JsonApiException $throwable */
            $errors   = $throwable->getErrors();
            $httpCode = $throwable->getHttpCode();
        } else {
            $errors   = new ErrorCollection();
            $httpCode = $this->getHttpCodeForUnexpectedThrowable();
            $details  = null;
            if ($this->isDebug === true) {
                $message = $throwable->getMessage();
                $details = (string)$throwable;
            }
            $errors->add(new Error(null, null, null, (string)$httpCode, null, $message, $details));
        }

        // encode the error and send to client
        $content = $this->encoder->encodeErrors($errors);

        return $this->createThrowableJsonApiResponse($throwable, $content, $httpCode);
    }
612050
public function convertExceptionToHtml($exception)
    {
        $flat = $this->getFlattenedException($exception);

        $handler = new SymfonyExceptionHandler();

        return $this->decorate($handler->getContent($flat), $handler->getStylesheet($flat), $flat);
    }
1105000
public function renderToFile(\Throwable $exception, string $file): bool
    {
        if ($handle = @\fopen($file, 'xb')) {
            \ob_start(); // double buffer prevents sending HTTP headers in some PHP
            \ob_start(function ($buffer) use ($handle) {
                \fwrite($handle, $buffer);
            }, 4096);
            $this->renderTemplate($exception, __DIR__ . '/assets/BlueScreen/page.phtml', false);
            \ob_end_flush();
            \ob_end_clean();
            \fclose($handle);

            return true;
        }

        return false;
    }
949621
public function handler(\Throwable $t) {
        //Write to log
        $this->toLog($t);

        if (!in_array(strtolower(Assist::getAppEnv()), ['dev', 'development', 'local'])) {
          //Write to log
          $this->toLog($t);

          //Write a user friendly message to output
          $msg = Assist::loadCoreView('whoops');

          return $this->toUserOutput($msg);
        }

        return $this->toOutput($t);
    }
442291
public static String[] render(final Throwable throwable) {

        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        try {
            throwable.printStackTrace(pw);
        } catch (RuntimeException ex) {
            // nothing to do
        }
        pw.flush();
        LineNumberReader reader = new LineNumberReader(new StringReader(sw.toString()));
        ArrayList<String> lines = new ArrayList<>();
        try {
            String line = reader.readLine();
            while (line != null) {
                lines.add(line);
                line = reader.readLine();
            }
        } catch (IOException ex) {
            if (ex instanceof InterruptedIOException) {
                Thread.currentThread().interrupt();
            }
            lines.add(ex.toString());
        }
        //String[] tempRep = new String[lines.size()];
        return lines.toArray(new String[0]);
    }
444016
protected function getExceptionAsXml(Throwable $exception): string
	{
		$details = $this->getStatusCodeAndMessage($exception);

		$xml = simplexml_load_string("<?xml version='1.0' encoding='utf-8'?><error />");

		$xml->addChild('code', $details['code']);

		$xml->addChild('message', $details['message']);

		return $xml->asXML();
	}
1231760
private function _throw() {
    $node = new ThrowStatementNode();
    $this->mustMatch(T_THROW, $node);
    $node->addChild($this->expr(), 'expression');
    $this->endStatement($node);
    return $node;
  }
642095
private function getNotificationMessage(Throwable $exception): string
    {
        if ($exception instanceof HttpExceptionInterface) {
            return $exception->getMessage();
        }

        $file = new SplFileInfo($exception->getFile());
        $line = $exception->getLine();

        $relativePathname = (new Filesystem())->makePathRelative($file->getPath(), $this->rootDir) . $file->getFilename();

        $message = $exception->getMessage();

        return sprintf('%s [in %s:%d]', $message, $relativePathname, $line);
    }
515858
public function getDescription( $throwException = TRUE )
	{
		$tags	= $this->getMetaTags( TRUE );
		if( isset( $tags['description'] ) )
			return $tags['description'];
		if( isset( $tags['dc.description'] ) )
			return $tags['dc.description'];
		if( $throwException )
			throw new RuntimeException( 'No Description Meta Tag set.' );
		return "";
	}
651100
public function render( \Throwable $e )
    {
        list( $file, $line ) = Util::caller(0);

        $title = 'CharcoalPHP: Exception List';

        if ( $this->clear_buffer ){
            ob_clean();
        }

        echo $this->_output( $e, $title, $file, $line );
    }
42033
public static function exceptionToResponse(\Throwable $exception): ResponseInterface
    {
        self::$reserved = null;

        if ($exception instanceof HttpErrorException) {
            $statusCode = $exception->getCode();
        } else {
            $userAgent = self::$request->getHeaderLine('User-Agent');
            $statusCode = $userAgent && \strpos($userAgent, 'MSIE ') !== false ? 503 : 500;
        }

        $headers = [];
        $template = 'html';
        $isHtmlMode = false;

        $accept = self::$request->getHeaderLine('Accept');
        foreach (static::$handlers as $template => $types) {
            foreach ($types as $type) {
                if (\stripos($accept, $type) !== false) {
                    $headers['Content-Type'] = $type;
                    break 2;
                }
            }
        }

        if ($headers === []) {
            $isHtmlMode = Helpers::isHtmlMode();

            if ($isHtmlMode) {
                $template = '500';
                $headers['Content-Type'] = 'text/html; charset=UTF-8';
            }
        }

        Helpers::improveException($exception);
        self::removeOutputBuffers(true);

        if (self::isProductionMode()) {
            try {
                self::log($exception, self::getExceptionLevel($exception));
            } catch (\Throwable $e) {
            }

            $body = self::exceptionTemplate($template, $exception, empty($e));
        } elseif ($isHtmlMode || Helpers::isAjax()) {
            $body = self::getBlueScreen()->render($exception);
        } else {
            $level = self::getExceptionLevel($exception);
            self::chromeLog($exception, $level);

            $s = Helpers::getClass($exception) . ($exception->getMessage() === '' ? '' : ': ' . $exception->getMessage())
                . ' in ' . $exception->getFile() . ':' . $exception->getLine()
                . "\nStack trace:\n" . $exception->getTraceAsString();
            try {
                $file = self::log($exception, $level);
                if ($file) {
                    $headers['X-Tracy-Error-Log'] = $file;
                }

                $body = "$s\n" . ($file ? "(stored in $file)\n" : '');
            } catch (\Throwable $e) {
                $body = "$s\nUnable to log error: {$e->getMessage()}\n";
            }
        }

        return self::writeToResponse(
            Factory::response($statusCode, $body, $headers)
        );
    }
298088
public function createResponse(Throwable $throwable, ContainerInterface $container): ThrowableResponseInterface
    {
        $message = 'Internal Server Error';

        $this->logException($throwable, $container, $message);

        $isDebug = $this->isDebug($container);
        if ($isDebug === true) {
            $run = new Run();

            // If these two options are not used it would work fine with PHP Unit and XDebug,
            // however it produces output to console under PhpDbg. So we need a couple of
            // tweaks to make it work predictably in both environments.
            //
            // this one forbids Whoops spilling output to console
            $run->writeToOutput(false);
            // by default after sending error to output Whoops stops execution
            // as we want just generated output `string` we instruct not to halt
            $run->allowQuit(false);

            $handler = new PlainTextHandler();
            $handler->setException($throwable);
            $run->pushHandler($handler);

            $text     = $run->handleException($throwable);
            $response = $this->createThrowableTextResponse($throwable, $text, static::DEFAULT_HTTP_ERROR_CODE);
        } else {
            $response = $this->createThrowableTextResponse($throwable, $message, static::DEFAULT_HTTP_ERROR_CODE);
        }

        return $response;
    }
156868
protected function render_renderable(renderable $renderable) {
        $o = $this->render_table($renderable);
        $o .= $this->render_add_button($renderable->courseid);

        return $o;
    }