fix: add guard to if & unless helpers #1549
The first time I read it (and without having a look at your issue) I thought it might be breaking, but there are actually no new exception, just different ones. In all sane cases at least.
I actually like it. Better error messages are always good.
This change should be generally safe.
The only way to be really sure is to apply the change, release it and roll back if someone complains. In my experience, breaking changes usually take less than a week to be noticed.
There are some things to consider:
Hey @nknapp, have updated this, adding tests and taking your feedback as far as I was able to for now.
What I did first was add a bunch of cases showing these inconsistent error messages for the if, unless and with helpers & commit that. I assume you'll squash this - it's just there to demonstrate the issues.
I've switched the logic from
I've then added a commit that implements the guards and shows the error messages change to become consistent and hopefully a bit clearer.
No other tests have to change for this to pass, so if there are any edge cases they are undocumented and untested.
I've not gone as far as a custom Exception class & typings - this is a bit beyond what I'm confident with just now - I'm not familiar with TypeScript. However, I do have other work I'd like to do with error handling, so time-permitting I'll revisit this whole area with some more improvements soooooon.
For now, I think this is a small change which offers some improvement