adrianbj / TracyDebugger

The ultimate debugging and development tool for ProcessWire
https://adrianbj.github.io/TracyDebugger/
GNU General Public License v2.0
87 stars 13 forks source link

Invalid argument supplied for foreach() error #63

Closed lesaff closed 2 years ago

lesaff commented 2 years ago

Got this error when trying to run a console.

Tracy Debugger version: 4.22.11 PW version: 3.0.185 dev PHP version: 7.4.22

>
Error: Invalid argument supplied for foreach() on line: 169 in ../site/modules/TracyDebugger/includes
/CodeProcessor.phpError: Invalid argument supplied for foreach() on line: 177 in ../site/modules/TracyDebugger
/includes/CodeProcessor.phpError: Invalid argument supplied for foreach() on line: 181 in ../site/modules
/TracyDebugger/includes/CodeProcessor.php 

CleanShot 2021-10-07 at 08 01 02

adrianbj commented 2 years ago

Hi @lesaff - I can't reproduce that on the latest PW dev. I feel like this might have been a weird one-off glitch where wire('session') isn't defined for some reason. If you can reproduce this, could you please narrow it down to wire('session') or wire('session')->tracyWhitelistData which is set here: https://github.com/adrianbj/TracyDebugger/blob/f5447ffef71caabf8ca759e3631cef1ad8ebb9d6/panels/ConsolePanel.php#L49

lesaff commented 2 years ago

Great guess! I was using Redis to store sessions. It works as soon as I uninstall it and switch back to the file-based session.

I am using a modified version of https://github.com/netcarver/PW-SessionHandlerRedis I've added PW3 compatibility and switched to predis instead of redis. I will see if I can debug further. It would be nice if I can still use it along with Tracy Debugger.

adrianbj commented 2 years ago

@lesaff - I can certainly add an isset() condition around that foreach() to prevent the error, but I do use $session in a few other places. Would it fix things for redis if I used $_SESSION instead? Or is there some other workaround we could employ?

lesaff commented 2 years ago

Since the redis session is just an extension to WireSessionHandler, shouldn't the session output be the same?

adrianbj commented 2 years ago

Maybe @netcarver might have some thoughts about this, given the connection to his Redis module?

adrianbj commented 2 years ago

@lesaff - I actually came across this recently myself and it should be fixed in https://github.com/adrianbj/TracyDebugger/commit/caa8428ec4752745373b0c81cbc082ead1cfbeb1 but please re-open if you continue to see it.