Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong namespace of exception handler #38

Closed
valentinhocher opened this issue Feb 6, 2015 · 5 comments
Closed

Wrong namespace of exception handler #38

valentinhocher opened this issue Feb 6, 2015 · 5 comments

Comments

@valentinhocher
Copy link

The namespace of the exception handler class seems to be hardcoded. Due to the PSR4 autoloader in L5 its best practice to rename the namespace of the app directory (http://laravel.com/docs/5.0/configuration#after-installation).

Fatal error: unknown class App\\Exceptions\\Handler in /usr/share/nginx/html/foo/bar/vendor/bugsnag/bugsnag-laravel/src/Bugsnag/BugsnagLaravel/BugsnagExceptionHandler.php on line 7

Handler.php is correctly namespaced, but wrong referenced in BugsnagExceptionHandler.php

use App\Exceptions\Handler as ExceptionHandler;
@adamgoose
Copy link
Contributor

Yeah, this is for sure an issue, and likely going to be incredibly difficult to fix.

@adamgoose
Copy link
Contributor

I was able to thwart this issue by doing the following:

  1. NOT include the BugsnagLaravelServiceProvider
  2. Using php artisan make:provider BugsnagServiceProvider
  3. Editing this provider to include the same register() method as the shipped provider.
  4. Updating my App\Exceptions\Handler (except it's not App), and replacing that report() method with the same report() method as the shipped handler.

@johnnygreen
Copy link

Also having this issue. Should bugsnag extend Illuminate\Foundation\Exceptions\Handler instead?

@johnnygreen
Copy link

An alt to doing what adamgoose suggested.

http://laravel.com/docs/5.0/errors#handling-errors

We can temp put this in the main handler:

app/Exceptions/Handler.php

public function report(Exception $e)
{
  $shouldReport = true;

  foreach ($this->dontReport as $type)
  {
      if ($e instanceof $type)
      {
          $shouldReport = false;
      }
  }

  if ($shouldReport) 
  {
     $bugsnag = \App::make('bugsnag');
     $bugsnag->notifyException($e);
  }

  return parent::report($e);
}

We need to override the singleton they bind in their service provider but keep all the rest of the functionality.

So then make your own exception service provider and place it right after the bugsnag one with this in it:

config/app.php

'providers' => ...
  'Bugsnag\BugsnagLaravel\BugsnagLaravelServiceProvider',
  'MyNamespace\Providers\ExceptionServiceProvider',

app/Providers/ExceptionServiceProvider.php

<?php namespace MyNamespace\Providers;

use Illuminate\Support\ServiceProvider;

class ExceptionServiceProvider extends ServiceProvider {

  public function boot()
  {
    $this->app->singleton('Illuminate\Contracts\Debug\ExceptionHandler', 'MyNamespace\Exceptions\Handler');
  }

  public function register(){}
}

@ConradIrwin
Copy link
Contributor

I'd love feedback on #40 — would that work for everyone?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants