| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7e23072 commit 77c69f7
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -60,6 +60,8 @@ function message(key, args) { | |||
| 60 | 60 | // Utility function for registering the error codes. Only used here. Exported | |
| 61 | 61 | // *only* to allow for testing. | |
| 62 | 62 | function E(sym, val) { | |
| 63 | + const assert = lazyAssert(); | ||
| 64 | + assert(messages.has(sym) === false, `Error symbol: ${sym} was already used.`); | ||
| 63 | 65 | messages.set(sym, typeof val === 'function' ? val : String(val)); | |
| 64 | 66 | } | |
| 65 | 67 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,6 +12,7 @@ const err1 = new errors.Error('TEST_ERROR_1', 'test'); | |||
| 12 | 12 | const err2 = new errors.TypeError('TEST_ERROR_1', 'test'); | |
| 13 | 13 | const err3 = new errors.RangeError('TEST_ERROR_1', 'test'); | |
| 14 | 14 | const err4 = new errors.Error('TEST_ERROR_2', 'abc', 'xyz'); | |
| 15 | + const err5 = new errors.Error('TEST_ERROR_1'); | ||
| 15 | 16 | ||
| 16 | 17 | assert(err1 instanceof Error); | |
| 17 | 18 | assert.strictEqual(err1.name, 'Error[TEST_ERROR_1]'); | |
@@ -33,6 +34,11 @@ assert.strictEqual(err4.name, 'Error[TEST_ERROR_2]'); | |||
| 33 | 34 | assert.strictEqual(err4.message, 'abc xyz'); | |
| 34 | 35 | assert.strictEqual(err4.code, 'TEST_ERROR_2'); | |
| 35 | 36 | ||
| 37 | + assert(err5 instanceof Error); | ||
| 38 | + assert.strictEqual(err5.name, 'Error[TEST_ERROR_1]'); | ||
| 39 | + assert.strictEqual(err5.message, 'Error for testing purposes: %s'); | ||
| 40 | + assert.strictEqual(err5.code, 'TEST_ERROR_1'); | ||
| 41 | + | ||
| 36 | 42 | assert.throws( | |
| 37 | 43 | () => new errors.Error('TEST_FOO_KEY'), | |
| 38 | 44 | /^AssertionError: An invalid error message key was used: TEST_FOO_KEY.$/); | |
@@ -118,3 +124,9 @@ assert.throws(() => { | |||
| 118 | 124 | type: TypeError, | |
| 119 | 125 | message: /^Error for testing 2/ })); | |
| 120 | 126 | }, /AssertionError: .+ does not match \S/); | |
| 127 | + | ||
| 128 | + assert.doesNotThrow(() => errors.E('TEST_ERROR_USED_SYMBOL')); | ||
| 129 | + assert.throws( | ||
| 130 | + () => errors.E('TEST_ERROR_USED_SYMBOL'), | ||
| 131 | + /^AssertionError: Error symbol: TEST_ERROR_USED_SYMBOL was already used\.$/ | ||
| 132 | + ); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments