spatie / laravel-ray

Debug with Ray to fix problems faster in Laravel apps
https://myray.app
MIT License
291 stars 64 forks source link

ray fails when dumping carbon objects with dd() #176

Closed pablosebastianr closed 3 years ago

pablosebastianr commented 3 years ago

When SEND_DUMPS_TO_RAY is true and a Carbon object is being dumped with dd(), ray throws an exception

Error Call to a member function getName() on string This occurs when calling Spatie\Ray\Payloads\CarbonPayload::getContent in vendor/spatie/ray/src/Payloads/CarbonPayload.php:32

Calling ray(now()) is fine though.

Versions spatie/laravel-ray package version: 1.12.6 PHP version: 7.3.23 Laravel version: 7.29

To Reproduce

  1. set SEND_DUMPS_TO_RAY to true in ray's config file
  2. dd(now())
patinthehat commented 3 years ago

@pablosebastianr I can't reproduce this issue - are you able to provide a small repo that demonstrates the error?

pablosebastianr commented 3 years ago

I made a repo to reproduce this https://psrodriguez@bitbucket.org/psrodriguez/raydddate.git

I just added a ray-dd command on routes/console.php and this is what I get when I call it

error-ray-console

It's a strange error, since I can dd( now()->timezone->getName() ) just fine, but it would seem at some point during the ray process the 'timezone' attribute on the carbon instance gets converted to string when I do dd(now()). But I'm just guessing.

I also changed the timezone to the default 'UTC' in config/app.php but same issue.

patinthehat commented 3 years ago

Thank you for creating that sample repo - but unfortunately I still can't reproduce the issue. I tested with both PHP 8 and PHP 7.4. Are you able to run PHP 7.4 instead of 7.3 and see if you still get an exception?

My guess is that the issue is caused by the DumpRecorder class converting the timezone property into a string. Using $this->carbon->timezoneName in CarbonPayload would probably resolve this issue.

If I manage to reproduce the error, I'll submit a PR.

pablosebastianr commented 3 years ago

Yes, certainly seems the case of the dd() call doing something to the carbon instance.

I dug up a bit deeper and ray(gettype($carbon->timezone)) in the CarbonPayload constructor shows 'object' when I use ray(now()) whereas it shows 'string' when I use dd(now()) Beyond that, I would have to dive too deep into the library.

I will try later with a different version of php and I'll let you know.

pablosebastianr commented 3 years ago

Well, this is what I tried:

PHP 7.3, on Ubuntu 20.04 (wsl 2), it doesn't work. PHP 7.4, on Ubuntu 20.04 (wsl 2), it works. PHP 7.3, on Debian 10 (wsl 2), it doesn't work. PHP 7.3, on Debian 10 (actual linux), it works.

So PHP 7.3 + WSL not 100% okay for Ray ?

freekmurze commented 3 years ago

I can't reproduce this, so closing for now.

We don't do anything special regarding Carbon, so I guess if there is a problem, it should be solved at Carbon's end.