Conversation
test/parallel/test-assert.js
Outdated
| 'a.doesNotThrow is not catching type matching errors'); | ||
|
|
||
| assert.throws(function() { assert.ifError(new Error('test error')); }); | ||
| assert.throws(function() { assert.ifError(new Error('test error')), /^([A-Za-z])\w+$/}); |
There was a problem hiding this comment.
This regexp is probably too general. Since the error being thrown here is known, can you change that to /^Error: test error$/?
There was a problem hiding this comment.
@joyeecheung I do not understand your request, can you please expound.
There was a problem hiding this comment.
In this repo we try to make the validation of the error message to be as concrete as possible. For example:
assert.throws(
() => {
throw new Error('Wrong value');
},
/^Error: Wrong value$/ // Instead of something like /Wrong value/
);There is an ongoing PR to update our guide on this: #11150
There was a problem hiding this comment.
In this line, since according to the documentation of assert.ifError(value):
Throws value if value is truthy.
We are checking that the truthy new Error('test error') passed to assert.ifError() should be rethrown, hence the error message from the block should be /^Error: test error$/
There was a problem hiding this comment.
@joyeecheung thanks for taking your time, I now get your point.
test/parallel/test-assert.js
Outdated
| 'a.doesNotThrow is not catching type matching errors'); | ||
|
|
||
| assert.throws(function() { assert.ifError(new Error('test error')); }); | ||
| assert.throws(function() { assert.ifError(new Error('test error')), /^Error: test error/}); |
There was a problem hiding this comment.
I think the regular expression should come after the }. Also, please add a $ to the end of the regex.
There was a problem hiding this comment.
@cjihrig thanks for pointing that out, I had missed the part that the regex is the optional argument to assert.throws()
test/parallel/test-assert.js
Outdated
| 'a.doesNotThrow is not catching type matching errors'); | ||
|
|
||
| assert.throws(function() { assert.ifError(new Error('test error')); }); | ||
| assert.throws(function() { assert.ifError(new Error('test error'))}, /^Error: test error$/); |
There was a problem hiding this comment.
You're going to need to add the semicolon back in.
There was a problem hiding this comment.
Also, please add a space before the closing curly brace for symmetry.
|
@abouthiroppy could you know why the tests are failing? |
|
Please fix this lint error. |
|
The long line has been fixed, but this is still returning a lint error due to indentation problems introduced in the fix for the log line. @jobala Please run |
|
@Trott Did you mean |
thefourtheye
left a comment
There was a problem hiding this comment.
LGTM if CI is green.
Argh! Yeah, |
|
@Trott thanks for the pointer. |
Verify error message thrown from assert.ifError PR-URL: #11193 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
|
landed in 5f20d62 |
Verify error message thrown from assert.ifError PR-URL: #11193 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Verify error message thrown from assert.ifError PR-URL: nodejs#11193 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Verify error message thrown from assert.ifError PR-URL: nodejs#11193 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Verify error message thrown from assert.ifError PR-URL: #11193 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
|
Needs a backport PR to land in v4 |
Verify error message thrown from assert.ifError PR-URL: #11193 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Description of task to be completed
Add a regular expression for
assert.throwsto validate the error message thrown.Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes