Johannes Schickling @schickling.dev · Apr 9

I highly recommend using a helper function like `shouldNeverHappen` instead of throwing errors directly in your code (only applies to defects/panics). It's an easy way to make your code more readable and improve DX by automatically opening the debugger during dev.

35 likes 6 replies

?

Replies

@kriszyp.name · Apr 9

The downside is that your console.error auto-prints the line number in `shouldNeverHappen` instead of in the actual code of `someFn`. Not a big downside though. This is still a good idea (and the Error's stack trace will still include all the relevant frames).

Zicklag · Apr 9

Whoa, here's a `debugger` keyword! I had no idea, that's cool.

Ray Thurn Void · Apr 9

This looks actually great! Love the debugger idea

Pachi · Apr 9

Interesting approach. I’m definitely trying this. Thanks Johannes!

Pearce Keesling · Apr 9

Is there a reason for going the "never" route instead of the typical "assert" route?

Johannes Schickling · Apr 9

Once you hit an a `shouldNeverHappen`, you automatically can debug interactively.