You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Why did startStackFunction get renamed to startStackFn from 8.x to 10.x #27671
In assert.AssertionError, for some reason options.startStackFunction got renamed to options.startStackFn from v8.x to v10.x
This means you have to do var e = new AssertionError({ startStackFn: fn, startStackFunction: fn }) to have code that works across both versions of nodejs.
This seems like an unnecessary breaking change :( is there no policy or code review for API stability ?
@Raynos that was a mistake on my side. I did not anticipate that the error class would actually really be used in the wild (it was not documented) and that this option would be used. I'll open a PR to accept both as valid options but that will probably not help a lot anymore.
@Raynos I believe you actually want to use the --unhandled-rejections=strict mode in that case. That is not yet available in Node.js < 11.x but it should be backported to at least 10.x.
@Raynos the cost should be identical in newer Node.js versions. I believe Node.js 8 is already fine with try / catch statements but I forgot in what version the performance cliff got removed.
There is one significant difference between these two versions though: the error message will be different (in case no message argument was passed through). Due to the abstraction, assert is not going to be able to determine the actual call site anymore but you said you want this only as safe guard that should actually never trigger.
Activity
BridgeAR commentedon May 13, 2019
@Raynos that was a mistake on my side. I did not anticipate that the error class would actually really be used in the wild (it was not documented) and that this option would be used. I'll open a PR to accept both as valid options but that will probably not help a lot anymore.
assert: add compatibility for older Node.js versions
BridgeAR commentedon May 13, 2019
I'll try to backport this as well.
Raynos commentedon May 14, 2019
@BridgeAR you are my hero.
Here is my use case for context.
I want to use
assert()but somehow bail outside of async/await; I want sanity assertions that should never happen and fail my program.I'll open an issue / PR on node core for this seperately as it's a useful issue that came up on twitter a while ago.
BridgeAR commentedon May 14, 2019
@Raynos I believe you actually want to use the
--unhandled-rejections=strictmode in that case. That is not yet available in Node.js < 11.x but it should be backported to at least 10.x.BridgeAR commentedon May 14, 2019
An easier solution would also be the following:
Raynos commentedon May 14, 2019
Your solution means i don't have an issue with the
AssertionErrorconstructor anymore. I didn't think about catching the error ...I'd have to write some benchmarks though. The existing
assert()calls are mostly free because they are a single if branch on a boolean.BridgeAR commentedon May 14, 2019
@Raynos the cost should be identical in newer Node.js versions. I believe Node.js 8 is already fine with
try / catchstatements but I forgot in what version the performance cliff got removed.There is one significant difference between these two versions though: the error message will be different (in case no
messageargument was passed through). Due to the abstraction, assert is not going to be able to determine the actual call site anymore but you said you want this only as safe guard that should actually never trigger.assert: add compatibility for older Node.js versions
assert: add compatibility for older Node.js versions