summaryrefslogtreecommitdiff
path: root/lib/internal/assert/assertion_error.js
AgeCommit message (Collapse)Author
2019-11-25lib: flatten access to primordialsMichaël Zasso
Store all primordials as properties of the primordials object. Static functions are prefixed by the constructor's name and prototype methods are prefixed by the constructor's name followed by "Prototype". For example: primordials.Object.keys becomes primordials.ObjectKeys. PR-URL: https://github.com/nodejs/node/pull/30610 Refs: https://github.com/nodejs/node/issues/29766 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2019-10-05lib: introduce no-mixed-operators eslint rule to libZYSzys
PR-URL: https://github.com/nodejs/node/pull/29834 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2019-07-25assert: avoid potentially misleading reference to object identityAnna Henningsen
Often, the word “identical” when referring to JS objects will be read as referring to having the same object identity (which is called “reference equality” here), but what the error message is trying to say here is that the objects are different but yield the same `util.inspect()` output. Since `util.inspect()` output represents the structure rather than the identity of objects, (hopefully) clarify the error message to reflect that. PR-URL: https://github.com/nodejs/node/pull/28824 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2019-06-12assert: print more lines in the error diffRuben Bridgewater
So far consequitive identical lines were collapsed if there were at least three. Now they are only collapsed from five identical lines on. This also simplifies the implementation a tiny bit by abstracting some logic. PR-URL: https://github.com/nodejs/node/pull/28058 Reviewed-By: Rich Trott <rtrott@gmail.com>
2019-06-12assert: fix error diffRuben Bridgewater
In some edge cases an identical line could be printed twice. This is now fixed by changing the algorithm a bit. It will now verify how many lines were identical before the current one. PR-URL: https://github.com/nodejs/node/pull/28058 Reviewed-By: Rich Trott <rtrott@gmail.com>
2019-06-12assert: limit string inspection when logging assertion errorsRuben Bridgewater
This makes sure long strings as `actual` or `expected` values on an `AssertionError` won't be logged completely. This is important as the actual value is somewhat redundant in combination with the error message which already logs the difference between the input values. PR-URL: https://github.com/nodejs/node/pull/28058 Reviewed-By: Rich Trott <rtrott@gmail.com>
2019-05-25assert: remove unreachable codeRich Trott
There is only one entry in `kReadableOperator` that ends in `Unequal`. So the value assigned on line 392 can only be truthy if `operator` is `notDeepEqual`. Therefore, the ternary condition on line 394 is always true. Remove the ternary. Coverage reports confirm that the removed code is unused. PR-URL: https://github.com/nodejs/node/pull/27840 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Beth Griggs <Bethany.Griggs@uk.ibm.com> Reviewed-By: Ouyang Yadong <oyydoibh@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2019-05-23assert: remove unreachable codeRich Trott
In lib/internal/assert/assertion_error.js, line 391 assures that `operator` is 'deepEqual' so there is no need to check the value of `operator` in a ternary on the next line (line 392). Remove the ternary. PR-URL: https://github.com/nodejs/node/pull/27786 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2019-05-16assert: remove unused codeRuben Bridgewater
Those two operators are not used. PR-URL: https://github.com/nodejs/node/pull/27676 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2019-05-16assert: add compatibility for older Node.js versionsRuben Bridgewater
This makes sure the `AssertionError` still accepts the `stackStartFunction` option as alternative to the `stackStartFn`. PR-URL: https://github.com/nodejs/node/pull/27672 Fixes: https://github.com/nodejs/node/issues/27671 Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2019-05-05assert: refine assertion messageRuben Bridgewater
This makes sure that the error message is more appropriate than before by checking closer what operator is used and which is not. It also increases the total number of lines printed to the user. PR-URL: https://github.com/nodejs/node/pull/27525 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
2019-04-12lib: enforce the use of Object from primordialsMichaël Zasso
PR-URL: https://github.com/nodejs/node/pull/27146 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gus Caplan <me@gus.host>
2019-04-03lib: force using primordials for JSON, Math and ReflectMichaël Zasso
Use the "no-restricted-globals" ESLint rule to lint for it. PR-URL: https://github.com/nodejs/node/pull/27027 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2019-04-03util: `inspect()` should not exceed `breakLength`Ruben Bridgewater
Using `util.inspect()` with the `compact` option set to a number could result in output that exceeded the `breakLength` option. This change makes sure that limit is taken into account. PR-URL: https://github.com/nodejs/node/pull/26914 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2019-03-30benchmark,lib: change var to constRuben Bridgewater
Refs: https://github.com/nodejs/node/pull/26679 PR-URL: https://github.com/nodejs/node/pull/26915 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Refael Ackermann <refack@gmail.com>
2019-03-24assert: reduce internal usage of public require of utiltoshi1127
PR-URL: https://github.com/nodejs/node/pull/26750 Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
2019-03-23assert: improve performance to instantiate errorsRuben Bridgewater
This improves the performance for AssertionError by deactivating duplicated stack frame creation. PR-URL: https://github.com/nodejs/node/pull/26738 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2019-03-23lib: validate Error.captureStackTrace() callsRuben Bridgewater
This adds a custom eslint rule to verify that `Error.captureStackTrace()` is only called if necessary. In most cases the helper function should be used instead. PR-URL: https://github.com/nodejs/node/pull/26738 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2019-03-23errors: update error nameRuben Bridgewater
This updates all Node.js errors by removing the `code` being part of the `name` property. Instead, the name is just changed once on instantiation, the stack is accessed to create the stack as expected and then the `name` property is set back to it's original form. PR-URL: https://github.com/nodejs/node/pull/26738 Fixes: https://github.com/nodejs/node/issues/26669 Fixes: https://github.com/nodejs/node/issues/20253 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2019-02-08assert: refactor internal assert.jsRich Trott
Move lib/internal/assert.js to lib/internal/assert/assertion_error.js. This is in preparation for making lib/internal/assert.js a tiny module for use in Node.js built-ins so that we can use `assert()` without having to load the entire ~1200 line `assert` module. PR-URL: https://github.com/nodejs/node/pull/25956 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Minwoo Jung <minwoo@nodesource.com>