lib, test: add duplicate symbol checking in E()

Add duplicate symbol checking in E() to avoid potential confusing
result. Increase coverage of internal/errors.

PR-URL: https://github.com/nodejs/node/pull/11829
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
This commit is contained in:
DavidCai authored and Franziska Hinkelmann committed 2017-03-15 17:09:33 +01:00
1 parent 5bd1642dd1
commit b5eccc4c7e
2 files changed
+14

No files matched your search

+2
View File
@@ -60,6 +60,8 @@ function message(key, args) {
// Utility function for registering the error codes. Only used here. Exported
// *only* to allow for testing.
function E(sym, val) {
const assert = lazyAssert();
assert(messages.has(sym) === false, `Error symbol: ${sym} was already used.`);
messages.set(sym, typeof val === 'function' ? val : String(val));
}