-
-
Notifications
You must be signed in to change notification settings - Fork 693
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ifError should throw its argument #369
Comments
Hi @Magomogo thanks for the issue. As far as I know, assert.ifError(false);
assert.ifError(null);
assert.ifError(undefined);
err(function () {
assert.ifError('foo');
}, "expected \'foo\' to be falsy"); If in doubt though, read the source. Here is Node.js' source for ifError, while here is chai's. Chai's is a little more complex, so it can interface with the standard assertion errors. Here's the Do you have a specific code example that isn't working? |
Hi, @keithamus! Thanks for answering. var assert = require('chai').assert,
error = new Error('Ouch!');
assert.ifError(error); It gives |
Ah. I should perhaps take some of my own advice and read the source! It does indeed behave differently. It seems like our version of ifError will throw an AssertionError if the given argument is not falsey, while node will throw the given argument. I can't really tell you why this is different - but I can say that it is unlikely going to change any time soon; we don't have metrics on how many users use this feature, but cannot reasonably change the behaviour without potentially breaking existing users' code. @Magomogo, if you're looking for the same behaviour as Node's |
I understand your concerns. However it's bad that one can't just replace standard |
Hey @keithamus , should there be a new 3.0 branch that I pull request to if I make this change? |
@cjqed I've just created a |
So, I tried to look up things about ifError, like how it came to be and the documentation surrounding it, but:
/*!
* Undocumented / untested
*/
assert.ifError = function (val) {
I'm not really sure what the expected behavior in 3.0 should be. Should we just mimic node behavior? assert.ifError = function (val) {
if (val) {
throw(val);
}
}; |
What is the |
Why
ifError(arg)
doesn't throw its argument as node.js' included assert module do?The text was updated successfully, but these errors were encountered: