laravel-rollbar icon indicating copy to clipboard operation
laravel-rollbar copied to clipboard

Exception stack trace gone in Laravel 5.5

Open zoltanpeto opened this issue 7 years ago • 8 comments

Hi,

We've recently upgraded our app to Laravel 5.5 and noticed that exceptions are not reported the way they used to be before: the stack trace is completely gone from the report page and only shows the exception message.

After some debugging I realised that it is due to how Laravel's exception handler logs the errors was changed: instead of using the exception instance as the log message (which is then picked up in this package's log listener), it uses the exception message instead and adds the instance itself to the log call's context.

I managed to work around this by adding a \Log::error($exception) call in the app's exception handler report method, but now everything is reported on Rollbar twice: once with and once without the stack trace.

I'm happy to contribute with a PR to fix this issue, let me know!

zoltanpeto avatar Sep 28 '17 08:09 zoltanpeto

To provide some more context of the issue:

L5.4 - Illuminate\Foundation\Exceptions\Handler:

public function report(Exception $e)
{
  if ($this->shouldntReport($e)) {
    return;
  }
  try {
    $logger = $this->container->make(LoggerInterface::class);
  } catch (Exception $ex) {
    throw $e; // throw the original exception
  }
  $logger->error($e);
}

L5.5 - Illuminate\Foundation\Exceptions\Handler:

public function report(Exception $e)
{
  if ($this->shouldntReport($e)) {
    return;
  }

  if (method_exists($e, 'report')) {
    return $e->report();
  }

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

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

zoltanpeto avatar Sep 28 '17 08:09 zoltanpeto

I'm experiencing this as well.

mitchjam avatar Oct 30 '17 12:10 mitchjam

I'm running into the same issue, did a little digging and I think this might be the offending PR where the change gets introduced: https://github.com/laravel/framework/pull/19698

Just putting it here to provide some more context.

EricTendian avatar Nov 07 '17 03:11 EricTendian

Any updates to this issue?

clin407 avatar Nov 22 '17 03:11 clin407

Hey everyone

This issue has been recently resolved in our officially supported laravel repo: https://github.com/rollbar/rollbar-php-laravel

PR https://github.com/rollbar/rollbar-php-laravel/pull/26 has addressed this.

ArturMoczulski avatar Nov 22 '17 14:11 ArturMoczulski

To understand the original report better, are you saying an app that was created with a 5.4 laravel skeleton has an issue when the framework is updated to 5.5? In new projects that use the 5.5 skeleton (laravel/laravel), I see both the whoops screen and the normal report screen (when whoops is removed), both have the stack trace and the exception message. Additionally, out the box logging (/storage/logs/laravel.log has a stringified version of the exception, as it did before).

It is entirely possible I missed a usage scenario where a 5.4 skeleton using the 5.5 framework might be impacted, and I'd be happy to document what would be expected in the upgrade process to make things work as they previously did.

(For reference, I made the original PR, sorry I am late in seeing this thread. The original PR was made to keep the usage inside laravel consistent to what monolog and psr7 are expecting in their parameters)

ralphschindler avatar Nov 29 '17 16:11 ralphschindler

I am using

"php": ">=7.0.0",
"fideloper/proxy": "~3.3",
"laravel/framework": "5.5.*",
"laravel/tinker": "~1.0",
"tymon/jwt-auth": "1.0.0-rc.1"

it worked here Add the following code to the render method within app/Exceptions/Handler.php

public function render($request, Exception $e)
    {
        if($e instanceof \Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException){
            return response()->json([$e->getMessage()], $e->getStatusCode());
        }
        return parent::render($request, $e);
    }

victorrss avatar Mar 06 '18 20:03 victorrss

Don't know if this is still open but in Laravel 5.7 you can use the get trace method on the exception like so. $stacktrace = $exception->getTrace(); This will return the stack trace for you.

thecodecafe avatar Sep 26 '18 18:09 thecodecafe