9
Finally realized my debug prints were hiding the real bug, not showing it
Spent 3 evenings hunting a login crash in my first real project. I kept adding console.log statements everywhere and the error only showed up after the log lines ran. Then it clicked, the logs themselves were changing the timing of the code. Removed them all, ran it again, and the crash happened instantly on line 14. A null value I was sure I handled was slipping through because my print statement was delaying the failure. Now I use a proper debugger and only add logs when I'm 100% sure they won't affect flow. Has anyone else had a print statement straight up mask a bug like that?
1 comments
Log in to join the discussion
Log In1 Comment
mileslane23d ago
lol I mean sure, that happens but three evenings seems like a stretch. You said the logs were changing timing and that made the bug show up later, but a crash is a crash. If line 14 was gonna fail, it was gonna fail whether you logged before it or not. The print statement didn't hide anything, it just moved where the crash happened. A debugger would've shown you the same null value, you just would've had to step into it. Honestly sounds like you just needed to read the traceback better instead of blaming the console.logs.
4