TritonDataCenter / node-assert-plus

Extra assertions on top of node's assert module
MIT License
122 stars 25 forks source link

assert.async #22

Open DonutEspresso opened 8 years ago

DonutEspresso commented 8 years ago

For modules that expose async public APIs, I often want to assert but want the assertion error returned via the callback. I do this frequently to avoid reimplementing non-throwing validation at the caller (i.e., a server handler), and to avoid usage of try/catch at the caller. I'm thinking a wrapper that takes a function of assertions and a callback:

assert.async(function() {
  assert.object(opts, 'opts');
  assert.number(opts.ttl, 'opts.ttl');
}, callback);

I realize this somewhat conflicts with the spirit and ethos of assertions. It's easy enough to wrap in userland, but figured it wouldn't hurt to ask if this seemed like something useful. Would be happy to file a PR if so - otherwise, feel free to close.

pfmooney commented 8 years ago

While I'm interested in further discussion, my inclination for assert-plus to stay synchronous at this point.