PureScript Debugging

Hello.

I’m wondering what tools/techniques others in the community use to debug their code? I’ve found a few different things, including a time-travel debugger, a basic “spy” interface that logs to the console, etc. So far, I’ve just been reading code. Thanks.

1 Like

Here’s what I have in my learning repo:

Half of debugging is just using types correctly, so that you can’t write incorrect code. The other half is using spy, traceM, purescript-debugger, and otherwise writing your code as a composition of small functions, so that you can easily test those functions in small pieces to help find the bug.

There’s also property-based testing, which can greatly help, but its usage is limited to specific circumstances.

3 Likes

Thanks, Jordan. I was looking for a way to spy values in other’s people’s code at runtime. So not so much using the debugger as a means of finding problems in code that I’m modifying anyway, just more of a way to understand the runtime behavior of a particular piece of code better.

I’m sure it is not a recommended way and I should keep this dirty secret for myself :stuck_out_tongue: but sometimes I find it really handy to directly debug JS output files. I mean inspecting values by modifying files in the ./output dir like ./output/Some.Module/index.js or ./output/Some.Module/foreign.js. I’m finding this method especially useful when writing/debugging FFI modules because my IDE setup doesn’t recompile PS on a JS modules change.
Of course during such a debug sessions I have to be careful to not override these files by compilation and to cleanup everything afterwards (by removing files and forcing the recompilation)… otherwise I can start debugging my own debug modifications :stuck_out_tongue:

2 Likes

I have also done this once or twice, lol