This package adds custom error message support to the stock `check`


#1

I often find the error messages from the stock meteor check package not that helpful. It would spit out what is wrong but the message is mostly not friendly or helpful enough to get an idea of how to fix the error. In the end I have to check the line that throws this error to see exactly what it means.

Sometimes I can get by with try blocks for throwing custom error messages for a couple of checks. But doing that for adding individual error messages for each check is very tedious. And it looks horrible:

function foo(name, age) {
  try {
    check(name, String);
  } catch (error) {
    throw new Error('Expect name to be a string.');
  }
  try {
    check(age, Number);
  } catch (error) {
    throw new Error('Expect age to be a number.');
  }
}

So I wrote this tiny helper package that makes check support an optional argument for custom error messages. Check it out here: https://atmospherejs.com/zodiase/check

Using it is just as simple as check(value, pattern, message) and if the check fails, message gets thrown out. More importantly using this package won’t break your existing code since the message argument is optional and without it the check functions (almost) exactly the same as the stock version.

Any feedbacks and suggestions are welcome! :smiley:


#2

Awesome package! thanks. Very few installs, but I find it very helpful.


#3

Nice Work! but how can I show the error messages in my client side HTML? What to do if I use Bootstrap alerts?