Symfony Exception

ErrorException

HTTP 500 Internal Server Error

file_exists(): open_basedir restriction in effect. File(unknown) is not within the allowed path(s): (/home/ghafoor2/domains/filenab.com/:/tmp/:/usr/local/php-7.4/lib/php/)

Exception

ErrorException

  1.         return $this;
  2.     }
  3.     public function get(string $fileName): array
  4.     {
  5.         if (! file_exists($fileName)) {
  6.             return [];
  7.         }
  8.         try {
  9.             $file = new File($fileName);
HandleExceptions->handleError(2, 'file_exists(): open_basedir restriction in effect. File(unknown) is not within the allowed path(s): (/home/ghafoor2/domains/filenab.com/:/tmp/:/usr/local/php-7.4/lib/php/)', '/home/ghafoor2/domains/filenab.com/vendor/facade/flare-client-php/src/Stacktrace/Codesnippet.php', 31, array('fileName' => 'unknown'))
  1.         return $this;
  2.     }
  3.     public function get(string $fileName): array
  4.     {
  5.         if (! file_exists($fileName)) {
  6.             return [];
  7.         }
  8.         try {
  9.             $file = new File($fileName);
  1.     public function toArray(): array
  2.     {
  3.         $codeSnippet = (new Codesnippet())
  4.             ->snippetLineCount(31)
  5.             ->surroundingLine($this->lineNumber)
  6.             ->get($this->file);
  7.         return [
  8.             'line_number' => $this->lineNumber,
  9.             'method' => $this->method,
  10.             'class' => $this->class,
  1.     }
  2.     public function toArray(): array
  3.     {
  4.         return array_map(function (Frame $frame) {
  5.             return $frame->toArray();
  6.         }, $this->frames);
  7.     }
  8.     public function firstApplicationFrame(): ?Frame
  9.     {
Stacktrace->Facade\FlareClient\Stacktrace\{closure}(object(Frame))
  1.     public function toArray(): array
  2.     {
  3.         return array_map(function (Frame $frame) {
  4.             return $frame->toArray();
  5.         }, $this->frames);
  6.     }
  7.     public function firstApplicationFrame(): ?Frame
  8.     {
  9.         foreach ($this->frames as $index => $frame) {
  1.             'exception_class' => $this->exceptionClass,
  2.             'seen_at' => $this->getCurrentTime(),
  3.             'message' => $this->message,
  4.             'glows' => $this->glows,
  5.             'solutions' => $this->solutions,
  6.             'stacktrace' => $this->stacktrace->toArray(),
  7.             'context' => $this->allContext(),
  8.             'stage' => $this->stage,
  9.             'message_level' => $this->messageLevel,
  10.             'open_frame_index' => $this->openFrameIndex,
  11.             'group_by' => $this->groupBy ?? GroupingTypes::TOP_FRAME,
  1.         }
  2.     }
  3.     public function report(): array
  4.     {
  5.         return $this->report->toArray();
  6.     }
  7.     public function jsonEncode($data): string
  8.     {
  9.         $jsonOptions JSON_PARTIAL_OUTPUT_ON_ERROR JSON_HEX_TAG JSON_HEX_APOS JSON_HEX_AMP JSON_HEX_QUOT;
  1.             'telescopeUrl' => $this->telescopeUrl(),
  2.             'shareEndpoint' => $this->shareEndpoint(),
  3.             'title' => $this->title(),
  4.             'config' => $this->config(),
  5.             'solutions' => $this->solutions(),
  6.             'report' => $this->report(),
  7.             'housekeepingEndpoint' => url(config('ignition.housekeeping_endpoint_prefix''_ignition')),
  8.             'styles' => $this->styles(),
  9.             'scripts' => $this->scripts(),
  10.             'tabs' => $this->tabs(),
  11.             'jsonEncode' => Closure::fromCallable([$this'jsonEncode']),
  1.     protected function renderException(ErrorPageViewModel $exceptionViewModel)
  2.     {
  3.         echo $this->renderer->render(
  4.             'errorPage',
  5.             $exceptionViewModel->toArray()
  6.         );
  7.     }
  8. }
  1.             $solutions
  2.         );
  3.         $viewModel->defaultTab($defaultTab$defaultTabProps);
  4.         $this->renderException($viewModel);
  5.     }
  6.     public function handleReport(Report $report$defaultTab null$defaultTabProps = [])
  7.     {
  8.         $viewModel = new ErrorPageViewModel(
  1.     }
  2.     public function handle(): ?int
  3.     {
  4.         try {
  5.             $this->errorPageHandler->handle($this->exception);
  6.         } catch (Error $error) {
  7.             // Errors aren't caught by Whoops.
  8.             // Convert the error to an exception and throw again.
  9.             throw new ErrorException(
  1.                 // The HandlerInterface does not require an Exception passed to handle()
  2.                 // and neither of our bundled handlers use it.
  3.                 // However, 3rd party handlers may have already relied on this parameter,
  4.                 // and removing it would be possibly breaking for users.
  5.                 $handlerResponse $handler->handle($exception);
  6.                 // Collect the content type for possible sending in the headers.
  7.                 $handlerContentType method_exists($handler'contentType') ? $handler->contentType() : null;
  8.                 if (in_array($handlerResponse, [Handler::LAST_HANDLERHandler::QUIT])) {
<?php

namespace Illuminate\Foundation\Exceptions;

use 
Exception;
use 
Illuminate\Auth\Access\AuthorizationException;
use 
Illuminate\Auth\AuthenticationException;
use 
Illuminate\Contracts\Container\BindingResolutionException;
use 
Illuminate\Contracts\Container\Container;
use 
Illuminate\Contracts\Debug\ExceptionHandler as ExceptionHandlerContract;
use 
Illuminate\Contracts\Support\Responsable;
use 
Illuminate\Database\Eloquent\ModelNotFoundException;
use 
Illuminate\Http\Exceptions\HttpResponseException;
use 
Illuminate\Http\JsonResponse;
use 
Illuminate\Http\RedirectResponse;
use 
Illuminate\Http\Response;
use 
Illuminate\Routing\Router;
use 
Illuminate\Session\TokenMismatchException;
use 
Illuminate\Support\Arr;
use 
Illuminate\Support\Facades\Auth;
use 
Illuminate\Support\Facades\View;
use 
Illuminate\Support\Reflector;
use 
Illuminate\Support\ViewErrorBag;
use 
Illuminate\Validation\ValidationException;
use 
Psr\Log\LoggerInterface;
use 
Symfony\Component\Console\Application as ConsoleApplication;
use 
Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer;
use 
Symfony\Component\HttpFoundation\Exception\SuspiciousOperationException;
use 
Symfony\Component\HttpFoundation\RedirectResponse as SymfonyRedirectResponse;
use 
Symfony\Component\HttpFoundation\Response as SymfonyResponse;
use 
Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use 
Symfony\Component\HttpKernel\Exception\HttpException;
use 
Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use 
Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use 
Throwable;
use 
Whoops\Handler\HandlerInterface;
use 
Whoops\Run as Whoops;

class 
Handler implements ExceptionHandlerContract
{
    
/**
     * The container implementation.
     *
     * @var \Illuminate\Contracts\Container\Container
     */
    
protected $container;

    
/**
     * A list of the exception types that are not reported.
     *
     * @var array
     */
    
protected $dontReport = [];

    
/**
     * A list of the internal exception types that should not be reported.
     *
     * @var array
     */
    
protected $internalDontReport = [
        
AuthenticationException::class,
        
AuthorizationException::class,
        
HttpException::class,
        
HttpResponseException::class,
        
ModelNotFoundException::class,
        
SuspiciousOperationException::class,
        
TokenMismatchException::class,
        
ValidationException::class,
    ];

    
/**
     * A list of the inputs that are never flashed for validation exceptions.
     *
     * @var array
     */
    
protected $dontFlash = [
        
'password',
        
'password_confirmation',
    ];

    
/**
     * Create a new exception handler instance.
     *
     * @param  \Illuminate\Contracts\Container\Container  $container
     * @return void
     */
    
public function __construct(Container $container)
    {
        
$this->container $container;
    }

    
/**
     * Report or log an exception.
     *
     * @param  \Throwable  $e
     * @return void
     *
     * @throws \Throwable
     */
    
public function report(Throwable $e)
    {
        if (
$this->shouldntReport($e)) {
            return;
        }

        if (
Reflector::isCallable($reportCallable = [$e'report'])) {
            
$this->container->call($reportCallable);

            return;
        }

        try {
            
$logger $this->container->make(LoggerInterface::class);
        } catch (
Exception $ex) {
            throw 
$e;
        }

        
$logger->error(
            
$e->getMessage(),
            
array_merge(
                
$this->exceptionContext($e),
                
$this->context(),
                [
'exception' => $e]
            )
        );
    }

    
/**
     * Determine if the exception should be reported.
     *
     * @param  \Throwable  $e
     * @return bool
     */
    
public function shouldReport(Throwable $e)
    {
        return ! 
$this->shouldntReport($e);
    }

    
/**
     * Determine if the exception is in the "do not report" list.
     *
     * @param  \Throwable  $e
     * @return bool
     */
    
protected function shouldntReport(Throwable $e)
    {
        
$dontReport array_merge($this->dontReport$this->internalDontReport);

        return ! 
is_null(Arr::first($dontReport, function ($type) use ($e) {
            return 
$e instanceof $type;
        }));
    }

    
/**
     * Get the default exception context variables for logging.
     *
     * @param  \Throwable  $e
     * @return array
     */
    
protected function exceptionContext(Throwable $e)
    {
        return [];
    }

    
/**
     * Get the default context variables for logging.
     *
     * @return array
     */
    
protected function context()
    {
        try {
            return 
array_filter([
                
'userId' => Auth::id(),
                
// 'email' => optional(Auth::user())->email,
            
]);
        } catch (
Throwable $e) {
            return [];
        }
    }

    
/**
     * Render an exception into an HTTP response.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Throwable  $e
     * @return \Symfony\Component\HttpFoundation\Response
     *
     * @throws \Throwable
     */
    
public function render($requestThrowable $e)
    {
        if (
method_exists($e'render') && $response $e->render($request)) {
            return 
Router::toResponse($request$response);
        } elseif (
$e instanceof Responsable) {
            return 
$e->toResponse($request);
        }

        
$e $this->prepareException($e);

        if (
$e instanceof HttpResponseException) {
            return 
$e->getResponse();
        } elseif (
$e instanceof AuthenticationException) {
            return 
$this->unauthenticated($request$e);
        } elseif (
$e instanceof ValidationException) {
            return 
$this->convertValidationExceptionToResponse($e$request);
        }

        return 
$request->expectsJson()
                    ? 
$this->prepareJsonResponse($request$e)
                    : 
$this->prepareResponse($request$e);
    }

    
/**
     * Prepare exception for rendering.
     *
     * @param  \Throwable  $e
     * @return \Throwable
     */
    
protected function prepareException(Throwable $e)
    {
        if (
$e instanceof ModelNotFoundException) {
            
$e = new NotFoundHttpException($e->getMessage(), $e);
        } elseif (
$e instanceof AuthorizationException) {
            
$e = new AccessDeniedHttpException($e->getMessage(), $e);
        } elseif (
$e instanceof TokenMismatchException) {
            
$e = new HttpException(419$e->getMessage(), $e);
        } elseif (
$e instanceof SuspiciousOperationException) {
            
$e = new NotFoundHttpException('Bad hostname provided.'$e);
        }

        return 
$e;
    }

    
/**
     * Convert an authentication exception into a response.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Illuminate\Auth\AuthenticationException  $exception
     * @return \Symfony\Component\HttpFoundation\Response
     */
    
protected function unauthenticated($requestAuthenticationException $exception)
    {
        return 
$request->expectsJson()
                    ? 
response()->json(['message' => $exception->getMessage()], 401)
                    : 
redirect()->guest($exception->redirectTo() ?? route('login'));
    }

    
/**
     * Create a response object from the given validation exception.
     *
     * @param  \Illuminate\Validation\ValidationException  $e
     * @param  \Illuminate\Http\Request  $request
     * @return \Symfony\Component\HttpFoundation\Response
     */
    
protected function convertValidationExceptionToResponse(ValidationException $e$request)
    {
        if (
$e->response) {
            return 
$e->response;
        }

        return 
$request->expectsJson()
                    ? 
$this->invalidJson($request$e)
                    : 
$this->invalid($request$e);
    }

    
/**
     * Convert a validation exception into a response.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Illuminate\Validation\ValidationException  $exception
     * @return \Illuminate\Http\Response
     */
    
protected function invalid($requestValidationException $exception)
    {
        return 
redirect($exception->redirectTo ?? url()->previous())
                    ->
withInput(Arr::except($request->input(), $this->dontFlash))
                    ->
withErrors($exception->errors(), $exception->errorBag);
    }

    
/**
     * Convert a validation exception into a JSON response.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Illuminate\Validation\ValidationException  $exception
     * @return \Illuminate\Http\JsonResponse
     */
    
protected function invalidJson($requestValidationException $exception)
    {
        return 
response()->json([
            
'message' => $exception->getMessage(),
            
'errors' => $exception->errors(),
        ], 
$exception->status);
    }

    
/**
     * Prepare a response for the given exception.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Throwable  $e
     * @return \Symfony\Component\HttpFoundation\Response
     */
    
protected function prepareResponse($requestThrowable $e)
    {
        if (! 
$this->isHttpException($e) && config('app.debug')) {
            return 
$this->toIlluminateResponse($this->convertExceptionToResponse($e), $e);
        }

        if (! 
$this->isHttpException($e)) {
            
$e = new HttpException(500$e->getMessage());
        }

        return 
$this->toIlluminateResponse(
            
$this->renderHttpException($e), $e
        
);
    }

    
/**
     * Create a Symfony response for the given exception.
     *
     * @param  \Throwable  $e
     * @return \Symfony\Component\HttpFoundation\Response
     */
    
protected function convertExceptionToResponse(Throwable $e)
    {
        return 
SymfonyResponse::create(
            
$this->renderExceptionContent($e),
            
$this->isHttpException($e) ? $e->getStatusCode() : 500,
            
$this->isHttpException($e) ? $e->getHeaders() : []
        );
    }

    
/**
     * Get the response content for the given exception.
     *
     * @param  \Throwable  $e
     * @return string
     */
    
protected function renderExceptionContent(Throwable $e)
    {
        try {
            return 
config('app.debug') && class_exists(Whoops::class)
                        ? 
$this->renderExceptionWithWhoops($e)
                        : 
$this->renderExceptionWithSymfony($econfig('app.debug'));
        } catch (
Exception $e) {
            return 
$this->renderExceptionWithSymfony($econfig('app.debug'));
        }
    }

    
/**
     * Render an exception to a string using "Whoops".
     *
     * @param  \Throwable  $e
     * @return string
     */
    
protected function renderExceptionWithWhoops(Throwable $e)
    {
        return 
tap(new Whoops, function ($whoops) {
            
$whoops->appendHandler($this->whoopsHandler());

            
$whoops->writeToOutput(false);

            
$whoops->allowQuit(false);
        })->
handleException($e);
    }

    
/**
     * Get the Whoops handler for the application.
     *
     * @return \Whoops\Handler\Handler
     */
    
protected function whoopsHandler()
    {
        try {
            return 
app(HandlerInterface::class);
        } catch (
BindingResolutionException $e) {
            return (new 
WhoopsHandler)->forDebug();
        }
    }

    
/**
     * Render an exception to a string using Symfony.
     *
     * @param  \Throwable  $e
     * @param  bool  $debug
     * @return string
     */
    
protected function renderExceptionWithSymfony(Throwable $e$debug)
    {
        
$renderer = new HtmlErrorRenderer($debug);

        return 
$renderer->render($e)->getAsString();
    }

    
/**
     * Render the given HttpException.
     *
     * @param  \Symfony\Component\HttpKernel\Exception\HttpExceptionInterface  $e
     * @return \Symfony\Component\HttpFoundation\Response
     */
    
protected function renderHttpException(HttpExceptionInterface $e)
    {
        
$this->registerErrorViewPaths();

        if (
view()->exists($view $this->getHttpExceptionView($e))) {
            return 
response()->view($view, [
                
'errors' => new ViewErrorBag,
                
'exception' => $e,
            ], 
$e->getStatusCode(), $e->getHeaders());
        }

        return 
$this->convertExceptionToResponse($e);
    }

    
/**
     * Register the error template hint paths.
     *
     * @return void
     */
    
protected function registerErrorViewPaths()
    {
        
$paths collect(config('view.paths'));

        
View::replaceNamespace('errors'$paths->map(function ($path) {
            return 
"{$path}/errors";
        })->
push(__DIR__.'/views')->all());
    }

    
/**
     * Get the view used to render HTTP exceptions.
     *
     * @param  \Symfony\Component\HttpKernel\Exception\HttpExceptionInterface  $e
     * @return string
     */
    
protected function getHttpExceptionView(HttpExceptionInterface $e)
    {
        return 
"errors::{$e->getStatusCode()}";
    }

    
/**
     * Map the given exception into an Illuminate response.
     *
     * @param  \Symfony\Component\HttpFoundation\Response  $response
     * @param  \Throwable  $e
     * @return \Illuminate\Http\Response
     */
    
protected function toIlluminateResponse($responseThrowable $e)
    {
        if (
$response instanceof SymfonyRedirectResponse) {
            
$response = new RedirectResponse(
                
$response->getTargetUrl(), $response->getStatusCode(), $response->headers->all()
            );
        } else {
            
$response = new Response(
                
$response->getContent(), $response->getStatusCode(), $response->headers->all()
            );
        }

        return 
$response->withException($e);
    }

    
/**
     * Prepare a JSON response for the given exception.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Throwable  $e
     * @return \Illuminate\Http\JsonResponse
     */
    
protected function prepareJsonResponse($requestThrowable $e)
    {
        return new 
JsonResponse(
            
$this->convertExceptionToArray($e),
            
$this->isHttpException($e) ? $e->getStatusCode() : 500,
            
$this->isHttpException($e) ? $e->getHeaders() : [],
            
JSON_PRETTY_PRINT JSON_UNESCAPED_SLASHES
        
);
    }

    
/**
     * Convert the given exception to an array.
     *
     * @param  \Throwable  $e
     * @return array
     */
    
protected function convertExceptionToArray(Throwable $e)
    {
        return 
config('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->isHttpException($e) ? $e->getMessage() : 'Server Error',
        ];
    }

    
/**
     * Render an exception to the console.
     *
     * @param  \Symfony\Component\Console\Output\OutputInterface  $output
     * @param  \Throwable  $e
     * @return void
     */
    
public function renderForConsole($outputThrowable $e)
    {
        (new 
ConsoleApplication)->renderThrowable($e$output);
    }

    
/**
     * Determine if the given exception is an HTTP exception.
     *
     * @param  \Throwable  $e
     * @return bool
     */
    
protected function isHttpException(Throwable $e)
    {
        return 
$e instanceof HttpExceptionInterface;
    }
}