We've had problems in the past with applications being very picky about how we do parameter validation, so I'd like to be proactive about getting that right, or at least not copy it from elsewhere without testing. The relevant tests are a bit tricky to read, so I've taken the liberty of adding them and adjusting the implementation appropriately; would you mind fixing up your patches accordingly?
[scratch.diff](/uploads/ecf33271bf2f18bce38f7ef6daf40aa7/scratch.diff)