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

Fatal error after upgrading to 7.2.0 #134

Closed
matt-h opened this issue Mar 30, 2022 · 8 comments · Fixed by rollbar/rollbar-php#562
Closed

Fatal error after upgrading to 7.2.0 #134

matt-h opened this issue Mar 30, 2022 · 8 comments · Fixed by rollbar/rollbar-php#562
Assignees

Comments

@matt-h
Copy link

matt-h commented Mar 30, 2022

I'm getting the following error every time it tries to log anything to Rollbar. This is using Laravel 8 with the following config.

'rollbar' => [
            'driver' => 'monolog',
            'handler' => \Rollbar\Laravel\MonologHandler::class,
            'access_token' => env('ROLLBAR_TOKEN'),
            'level' => 'debug',
            'person_fn' => 'Auth::user',
            'capture_email' => true,   // optional
            'capture_username' => true, // optional
],
production.ERROR: Uncaught TypeError: Rollbar\Payload\Person::__construct(): Argument #1 ($id) must be of type string, int given, called in /srv/http/vendor/rollbar/rollbar/src/DataBuilder.php on line 916 and defined in /srv/http/vendor/rollbar/rollbar/src/Payload/Person.php:18
Stack trace:
#0 /srv/http/vendor/rollbar/rollbar/src/DataBuilder.php(916): Rollbar\Payload\Person->__construct(1, '...', '...', Array)
#1 /srv/http/vendor/rollbar/rollbar/src/DataBuilder.php(384): Rollbar\DataBuilder->getPerson()
#2 /srv/http/vendor/rollbar/rollbar/src/Config.php(725): Rollbar\DataBuilder->makeData('...', Object(TypeError), Array)
#3 /srv/http/vendor/rollbar/rollbar/src/RollbarLogger.php(215): Rollbar\Config->getRollbarData('...', Object(TypeError), Array)
#4 /srv/http/vendor/rollbar/rollbar/src/RollbarLogger.php(120): Rollbar\RollbarLogger->getPayload('...', '...', Object(TypeError), Array)
#5 /srv/http/vendor/rollbar/rollbar/src/Handlers/ExceptionHandler.php(28): Rollbar\RollbarLogger->log('...', Object(TypeError), Array)
#6 [internal function]: Rollbar\Handlers\ExceptionHandler->handle(Object(TypeError))
#7 {main}
  thrown {"userId":1,"exception":"[object] (Symfony\\Component\\ErrorHandler\\Error\\FatalError(code: 0): Uncaught TypeError: Rollbar\\Payload\\Person::__construct(): Argument #1 ($id) must be of type string, int given, called in /srv/http/vendor/rollbar/rollbar/src/DataBuilder.php on line 916 and defined in /srv/http/vendor/rollbar/rollbar/src/Payload/Person.php:18
Stack trace:
#0 /srv/http/vendor/rollbar/rollbar/src/DataBuilder.php(916): Rollbar\\Payload\\Person->__construct(1, '...', '...', Array)
#1 /srv/http/vendor/rollbar/rollbar/src/DataBuilder.php(384): Rollbar\\DataBuilder->getPerson()
#2 /srv/http/vendor/rollbar/rollbar/src/Config.php(725): Rollbar\\DataBuilder->makeData('...', Object(TypeError), Array)
#3 /srv/http/vendor/rollbar/rollbar/src/RollbarLogger.php(215): Rollbar\\Config->getRollbarData('...', Object(TypeError), Array)
#4 /srv/http/vendor/rollbar/rollbar/src/RollbarLogger.php(120): Rollbar\\RollbarLogger->getPayload('...', '...', Object(TypeError), Array)
#5 /srv/http/vendor/rollbar/rollbar/src/Handlers/ExceptionHandler.php(28): Rollbar\\RollbarLogger->log('...', Object(TypeError), Array)
#6 [internal function]: Rollbar\\Handlers\\ExceptionHandler->handle(Object(TypeError))
#7 {main}
  thrown at /srv/http/vendor/rollbar/rollbar/src/Payload/Person.php:18)
[stacktrace]
#0 {main}
"}
@cyrusradfar
Copy link

👋🏽 we will follow up, @matt-h -- thanks for reporting.

@danielmorell
Copy link
Collaborator

Hi @matt-h, thank you for opening this issue!

In rollbar/rollbar v3.0.0 we added strong typing to this property as a string. This may have been a mistake. It should probably be a union type string | int. It seems pretty reasonable that the ID would be an int for relational DBs and a string for document DBs.

If we were not using constructor property promotion, the constructor could accept and string | int and then cast an int to a string. This would allow us to strongly type the property as a string. It looks like it should be a string in the API docs.

I feel like this would be the simplest solution. Are there any there primitive types we should natively support other than string and int that we reasonably believe people could use as IDs?

@matt-h
Copy link
Author

matt-h commented Mar 30, 2022

I can't think of anything besides string or int that would be used as an ID.

It might make sense to keep the ID in src/Payload/Person.php as a string.

And then here: https://github.com/rollbar/rollbar-php/blob/4cf5c77c7b9be5e7fb3223361faa7fa2442c6cbd/src/DataBuilder.php#L916
Cast it to a string.

@danielmorell
Copy link
Collaborator

Casting to a string in the DataBuilder class is great idea. I double checked to make sure it is the only place we instantiate a Person instance. It is the only place. I have created a PR rollbar/rollbar-php#562 with the solution.

Thank you @matt-h for your help on this!

@danielmorell
Copy link
Collaborator

I have released v3.1.2 which should resolve the issue.

@chrillep
Copy link

@danielmorell have you bumped rollbar-laravel aswell ?

@danielmorell
Copy link
Collaborator

Hi @chrillep, No. I have not. There should be no need. You can simply run the following terminal command in your project directory.

$ composer update rollbar/rollbar

It should update rollbar/rollbar to v3.1.2.

@chrillep
Copy link

chrillep commented Apr 1, 2022

Hi @chrillep, No. I have not. There should be no need. You can simply run the following terminal command in your project directory.

$ composer update rollbar/rollbar

It should update rollbar/rollbar to v3.1.2.

@danielmorell yep that worked! cheers!
but dependabot didn't pick it up fyi :)

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

Successfully merging a pull request may close this issue.

4 participants