Skip to content

Support Generic Users#207

Merged
kattrali merged 2 commits into
bugsnag:masterfrom
mrsimonbennett:master
Jun 13, 2017
Merged

Support Generic Users#207
kattrali merged 2 commits into
bugsnag:masterfrom
mrsimonbennett:master

Conversation

@mrsimonbennett

Copy link
Copy Markdown
Contributor

When using the database auth driver in Laravel the generic user does not have a toArray() method. Resulting in a white screen of death.

Leaving with the options

  • You could turn off user in bugsnag and loss that information
  • Create a registerUserResolver and do what this PR does

However, I feel enough users must experience this out of the box and just get a white screen.

I have used reflection which seems less than ideal but open to ideas.

2016/10/03 14:25:21 [error] 2727#2727: *383 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught Error: Call to undefined method Illuminate\Auth\GenericUser::toArray() in /var/www/vendor/bugsnag/bugsnag-laravel/src/BugsnagServiceProvider.php:270
Stack trace:
#0 /var/www/vendor/bugsnag/bugsnag/src/Callbacks/CustomUser.php(41): Bugsnag\BugsnagLaravel\BugsnagServiceProvider->Bugsnag\BugsnagLaravel\{closure}()
#1 /var/www/vendor/bugsnag/bugsnag/src/Middleware/CallbackBridge.php(40): Bugsnag\Callbacks\CustomUser->__invoke(Object(Bugsnag\Report))
#2 [internal function]: Bugsnag\Middleware\CallbackBridge->__invoke(Object(Bugsnag\Report), Object(Closure))
#3 /var/www/vendor/bugsnag/bugsnag/src/Pipeline.php(68): call_user_func(Object(Bugsnag\Middleware\CallbackBridge), Object(Bugsnag\Report), Object(Closure))
#4 /var/www/vendor/bugsnag/bugsnag/src/Middleware/CallbackBridge.php(41): Bugsnag\Pipeline->Bugsnag\{closure}(Object(Bugsnag\Report))
#5 [internal function]: Bugsnag\Middleware\CallbackBridge->__invoke(Object(Bugsnag\Report), Object(Closure))
#6 /var/www/vendor/bug...

@mrsimonbennett
mrsimonbennett force-pushed the master branch 3 times, most recently from 196e099 to 4043812 Compare October 3, 2016 14:58
@GrahamCampbell

Copy link
Copy Markdown
Contributor

Seems a bit hacky to use refection to get at attributes. Does that class not provide a public interface?

1 similar comment
@GrahamCampbell

Copy link
Copy Markdown
Contributor

Seems a bit hacky to use refection to get at attributes. Does that class not provide a public interface?

@mrsimonbennett

Copy link
Copy Markdown
Contributor Author

I went with this approach because the generic user is a run on magic methods. Short of guessing what attribute keys are used this seemed the best approach which would work no matter how you modelled the generic user. I also thought as this only runs during an error report it was not too much of a technical cost.

If you have any ideas on a better approach I am happy to rewrite.

@mrsimonbennett

Copy link
Copy Markdown
Contributor Author

@GrahamCampbell any thoughts

@GrahamCampbell

Copy link
Copy Markdown
Contributor

We should probably also check if toArray is actually callable too.

@GrahamCampbell

Copy link
Copy Markdown
Contributor

Ok, I've made that change. I think this looks good now. 👍

@GrahamCampbell

Copy link
Copy Markdown
Contributor

A remark for other reviewers: PHP does not attempt to load classes in an instanceof check, so it doesn't matter if we do an instanceof check of a class that isn't known about.

@mrsimonbennett

Copy link
Copy Markdown
Contributor Author

Thanks

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 this pull request may close these issues.

3 participants