jenssegers / laravel-rollbar

Rollbar error monitoring integration for Laravel projects
328 stars 98 forks source link

artisan clear-compiled fails if the access token is not configured #44

Closed sgtlambda closed 8 years ago

sgtlambda commented 8 years ago

My deployment script packages the build in a separate directory where the .env file is not present (and thus the access token is empty). When php artisan clear-compiled is ran, the build halts with the following error:

  [RuntimeException]                                                                                                                                                                                                                                                   
  Error Output: PHP Fatal error:  Uncaught exception 'InvalidArgumentException' with message 'Rollbar access token not configured' in [..]/vendor/jenssegers/rollbar/src/RollbarServiceProvider.php:51  
  Stack trace:                

For the sake of context, I have my services.php configured as follows:

    'rollbar' => [
        'access_token' => env('ROLLBAR_ACCESS_TOKEN'),
        'level'        => env('ROLLBAR_LEVEL')
    ],

I think a solution would be to make the access_token an optional configuration parameter, in such a way that the rollbar log handler simply does not register if it is not set. Am I welcome to submit a PR?

Smashmint commented 8 years ago

Same problem here, i think you are always welcome to submit a PR :)

jenssegers commented 8 years ago

Will change this behaviour.

jenssegers commented 8 years ago

Check v1.5.0

v3rron commented 7 years ago

Still getting this error when I run php artisan migrate:refresh.

PHP Fatal error:  Uncaught InvalidArgumentException: Rollbar access token not configured in /var/www/vendor/jenssegers/rollbar/src/RollbarServiceProvider.php:67

Using latest version of laravel-rollbar v1.5.1 Using laravel v5.1.45 Here's my code in AppServiceProvider:

public function boot()
{
   if ($this->app->environment('production') && !empty(env('ROLLBAR_TOKEN'))) {
       $this->app->register(RollbarServiceProvider::class);
   }
}

The weird thing is I'm getting this exception when I'm on my local environment where I don't want to run Rollbar. In the .env file I have those 2 variables:

ROLLBAR_TOKEN=
ROLLBAR_LEVEL=debug

And here's app/services.php file:

'rollbar' => [
        'access_token' => env('ROLLBAR_TOKEN', ''),
        'level' => env('ROLLBAR_LEVEL', 'error'),
    ],
jishcem commented 7 years ago

I have the same problem. My APP_ENV is set to local and I dont want to configure Rollbar in local.

https://github.com/jenssegers/laravel-rollbar/blob/master/src/RollbarServiceProvider.php#L49

Does not really go inside if condition because I have $this->app['config']->get('services.rollbar') not empty.

Can it be if (! getenv('ROLLBAR_TOKEN') and ! $this->app['config']->get('services.rollbar.access_token'))

thebrubaker commented 7 years ago

Rollbar checks if the config value is empty, and throws the exception, so an empty string won't work. I set a default value of 'none' in my config/services file. That also means if you have ROLLBAR_TOKEN= in your .env file, then it will set an empty string as the value, and the exception will be thrown.

'rollbar' => [
    'access_token' => env('ROLLBAR_TOKEN', 'none'),
    'level' => env('ROLLBAR_LEVEL', 'error'),
]

It might be a good idea if this package is updated to let an empty string pass through without throwing an exception, and throw the exception when the user attempts to use the logger. There are going to be valid situations where an empty string is going to be set as the config value, so the package should account for it without breaking artisan.

jasonmccreary commented 5 years ago

Unfortunately setting the TOKEN to none as suggested above no longer seems to work:

'access_token' must be 32 characters long, was 'none'