| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 58be6ef commit b89d817
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -79,16 +79,6 @@ function inspectValue(val) { | |||
| 79 | 79 | ).split('\n'); | |
| 80 | 80 | } | |
| 81 | 81 | ||
| 82 | - function sysErrorMessage(prefix, ctx) { | ||
| 83 | - let message = `${prefix}: ${ctx.syscall} returned ` + | ||
| 84 | - `${ctx.code} (${ctx.message})`; | ||
| 85 | - if (ctx.path !== undefined) | ||
| 86 | - message += ` ${ctx.path}`; | ||
| 87 | - if (ctx.dest !== undefined) | ||
| 88 | - message += ` => ${ctx.dest}`; | ||
| 89 | - return message; | ||
| 90 | - } | ||
| 91 | - | ||
| 92 | 82 | // A specialized Error that includes an additional info property with | |
| 93 | 83 | // additional information about the error condition. | |
| 94 | 84 | // It has the properties present in a UVException but with a custom error | |
@@ -98,9 +88,17 @@ function sysErrorMessage(prefix, ctx) { | |||
| 98 | 88 | // The context passed into this error must have .code, .syscall and .message, | |
| 99 | 89 | // and may have .path and .dest. | |
| 100 | 90 | class SystemError extends Error { | |
| 101 | - constructor(key, context = {}) { | ||
| 102 | - context = context || {}; | ||
| 103 | - super(sysErrorMessage(message(key), context)); | ||
| 91 | + constructor(key, context) { | ||
| 92 | + const prefix = getMessage(key, []); | ||
| 93 | + let message = `${prefix}: ${context.syscall} returned ` + | ||
| 94 | + `${context.code} (${context.message})`; | ||
| 95 | + | ||
| 96 | + if (context.path !== undefined) | ||
| 97 | + message += ` ${context.path}`; | ||
| 98 | + if (context.dest !== undefined) | ||
| 99 | + message += ` => ${context.dest}`; | ||
| 100 | + | ||
| 101 | + super(message); | ||
| 104 | 102 | Object.defineProperty(this, kInfo, { | |
| 105 | 103 | configurable: false, | |
| 106 | 104 | enumerable: false, | |
@@ -183,16 +181,16 @@ class SystemError extends Error { | |||
| 183 | 181 | ||
| 184 | 182 | function makeSystemErrorWithCode(key) { | |
| 185 | 183 | return class NodeError extends SystemError { | |
| 186 | - constructor(...args) { | ||
| 187 | - super(key, ...args); | ||
| 184 | + constructor(ctx) { | ||
| 185 | + super(key, ctx); | ||
| 188 | 186 | } | |
| 189 | 187 | }; | |
| 190 | 188 | } | |
| 191 | 189 | ||
| 192 | 190 | function makeNodeErrorWithCode(Base, key) { | |
| 193 | 191 | return class NodeError extends Base { | |
| 194 | 192 | constructor(...args) { | |
| 195 | - super(message(key, args)); | ||
| 193 | + super(getMessage(key, args)); | ||
| 196 | 194 | } | |
| 197 | 195 | ||
| 198 | 196 | get name() { | |
@@ -485,7 +483,7 @@ function internalAssert(condition, message) { | |||
| 485 | 483 | } | |
| 486 | 484 | } | |
| 487 | 485 | ||
| 488 | - function message(key, args = []) { | ||
| 486 | + function getMessage(key, args) { | ||
| 489 | 487 | const msg = messages.get(key); | |
| 490 | 488 | if (util === undefined) util = require('util'); | |
| 491 | 489 | ||
@@ -694,7 +692,7 @@ module.exports = { | |||
| 694 | 692 | exceptionWithHostPort, | |
| 695 | 693 | uvException, | |
| 696 | 694 | isStackOverflowError, | |
| 697 | - message, | ||
| 695 | + getMessage, | ||
| 698 | 696 | AssertionError, | |
| 699 | 697 | SystemError, | |
| 700 | 698 | codes, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,7 +2,7 @@ | |||
| 2 | 2 | 'use strict'; | |
| 3 | 3 | const common = require('../common'); | |
| 4 | 4 | const assert = require('assert'); | |
| 5 | - const errors = require('internal/errors'); | ||
| 5 | + const { codes: { ERR_INDEX_OUT_OF_RANGE } } = require('internal/errors'); | ||
| 6 | 6 | const SIZE = 28; | |
| 7 | 7 | ||
| 8 | 8 | const buf1 = Buffer.allocUnsafe(SIZE); | |
@@ -214,13 +214,11 @@ function genBuffer(size, args) { | |||
| 214 | 214 | return b.fill(0).fill.apply(b, args); | |
| 215 | 215 | } | |
| 216 | 216 | ||
| 217 | - | ||
| 218 | 217 | function bufReset() { | |
| 219 | 218 | buf1.fill(0); | |
| 220 | 219 | buf2.fill(0); | |
| 221 | 220 | } | |
| 222 | 221 | ||
| 223 | - | ||
| 224 | 222 | // This is mostly accurate. Except write() won't write partial bytes to the | |
| 225 | 223 | // string while fill() blindly copies bytes into memory. To account for that an | |
| 226 | 224 | // error will be thrown if not all the data can be written, and the SIZE has | |
@@ -237,8 +235,9 @@ function writeToFill(string, offset, end, encoding) { | |||
| 237 | 235 | end = buf2.length; | |
| 238 | 236 | } | |
| 239 | 237 | ||
| 238 | + // Should never be reached. | ||
| 240 | 239 | if (offset < 0 || end > buf2.length) | |
| 241 | - throw new errors.RangeError('ERR_INDEX_OUT_OF_RANGE'); | ||
| 240 | + throw new ERR_INDEX_OUT_OF_RANGE(); | ||
| 242 | 241 | ||
| 243 | 242 | if (end <= offset) | |
| 244 | 243 | return buf2; | |
@@ -266,7 +265,6 @@ function writeToFill(string, offset, end, encoding) { | |||
| 266 | 265 | return buf2; | |
| 267 | 266 | } | |
| 268 | 267 | ||
| 269 | - | ||
| 270 | 268 | function testBufs(string, offset, length, encoding) { | |
| 271 | 269 | bufReset(); | |
| 272 | 270 | buf1.fill.apply(buf1, arguments); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,20 +3,18 @@ | |||
| 3 | 3 | ||
| 4 | 4 | require('../common'); | |
| 5 | 5 | const assert = require('assert'); | |
| 6 | - const errors = require('internal/errors'); | ||
| 7 | - | ||
| 8 | - const { E, SystemError } = errors; | ||
| 6 | + const { E, SystemError, codes } = require('internal/errors'); | ||
| 9 | 7 | ||
| 10 | 8 | assert.throws( | |
| 11 | - () => { throw new errors.SystemError(); }, | ||
| 9 | + () => { throw new SystemError(); }, | ||
| 12 | 10 | { | |
| 13 | 11 | name: 'TypeError', | |
| 14 | 12 | message: 'Cannot read property \'match\' of undefined' | |
| 15 | 13 | } | |
| 16 | 14 | ); | |
| 17 | 15 | ||
| 18 | 16 | E('ERR_TEST', 'custom message', SystemError); | |
| 19 | - const { ERR_TEST } = errors.codes; | ||
| 17 | + const { ERR_TEST } = codes; | ||
| 20 | 18 | ||
| 21 | 19 | { | |
| 22 | 20 | const ctx = { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -93,100 +93,95 @@ common.expectsError(() => { | |||
| 93 | 93 | }); | |
| 94 | 94 | ||
| 95 | 95 | // Test ERR_INVALID_FD_TYPE | |
| 96 | - assert.strictEqual(errors.message('ERR_INVALID_FD_TYPE', ['a']), | ||
| 96 | + assert.strictEqual(errors.getMessage('ERR_INVALID_FD_TYPE', ['a']), | ||
| 97 | 97 | 'Unsupported fd type: a'); | |
| 98 | 98 | ||
| 99 | 99 | // Test ERR_INVALID_URL_SCHEME | |
| 100 | - assert.strictEqual(errors.message('ERR_INVALID_URL_SCHEME', ['file']), | ||
| 100 | + assert.strictEqual(errors.getMessage('ERR_INVALID_URL_SCHEME', ['file']), | ||
| 101 | 101 | 'The URL must be of scheme file'); | |
| 102 | - assert.strictEqual(errors.message('ERR_INVALID_URL_SCHEME', [['file']]), | ||
| 102 | + assert.strictEqual(errors.getMessage('ERR_INVALID_URL_SCHEME', [['file']]), | ||
| 103 | 103 | 'The URL must be of scheme file'); | |
| 104 | - assert.strictEqual(errors.message('ERR_INVALID_URL_SCHEME', [['http', 'ftp']]), | ||
| 104 | + assert.strictEqual(errors.getMessage('ERR_INVALID_URL_SCHEME', | ||
| 105 | + [['http', 'ftp']]), | ||
| 105 | 106 | 'The URL must be one of scheme http or ftp'); | |
| 106 | - assert.strictEqual(errors.message('ERR_INVALID_URL_SCHEME', [['a', 'b', 'c']]), | ||
| 107 | + assert.strictEqual(errors.getMessage('ERR_INVALID_URL_SCHEME', | ||
| 108 | + [['a', 'b', 'c']]), | ||
| 107 | 109 | 'The URL must be one of scheme a, b, or c'); | |
| 108 | 110 | common.expectsError( | |
| 109 | - () => errors.message('ERR_INVALID_URL_SCHEME', [[]]), | ||
| 111 | + () => errors.getMessage('ERR_INVALID_URL_SCHEME', [[]]), | ||
| 110 | 112 | { | |
| 111 | 113 | code: 'ERR_ASSERTION', | |
| 112 | 114 | type: assert.AssertionError, | |
| 113 | 115 | message: /^At least one expected value needs to be specified$/ | |
| 114 | 116 | }); | |
| 115 | 117 | ||
| 116 | 118 | // Test ERR_MISSING_ARGS | |
| 117 | - assert.strictEqual(errors.message('ERR_MISSING_ARGS', ['name']), | ||
| 119 | + assert.strictEqual(errors.getMessage('ERR_MISSING_ARGS', ['name']), | ||
| 118 | 120 | 'The "name" argument must be specified'); | |
| 119 | - assert.strictEqual(errors.message('ERR_MISSING_ARGS', ['name', 'value']), | ||
| 121 | + assert.strictEqual(errors.getMessage('ERR_MISSING_ARGS', ['name', 'value']), | ||
| 120 | 122 | 'The "name" and "value" arguments must be specified'); | |
| 121 | - assert.strictEqual(errors.message('ERR_MISSING_ARGS', ['a', 'b', 'c']), | ||
| 123 | + assert.strictEqual(errors.getMessage('ERR_MISSING_ARGS', ['a', 'b', 'c']), | ||
| 122 | 124 | 'The "a", "b", and "c" arguments must be specified'); | |
| 123 | - common.expectsError( | ||
| 124 | - () => errors.message('ERR_MISSING_ARGS'), | ||
| 125 | - { | ||
| 126 | - code: 'ERR_ASSERTION', | ||
| 127 | - type: assert.AssertionError, | ||
| 128 | - message: /^At least one arg needs to be specified$/ | ||
| 129 | - }); | ||
| 130 | 125 | ||
| 131 | 126 | // Test ERR_SOCKET_BAD_PORT | |
| 132 | 127 | assert.strictEqual( | |
| 133 | - errors.message('ERR_SOCKET_BAD_PORT', [0]), | ||
| 128 | + errors.getMessage('ERR_SOCKET_BAD_PORT', [0]), | ||
| 134 | 129 | 'Port should be > 0 and < 65536. Received 0.'); | |
| 135 | 130 | ||
| 136 | 131 | // Test ERR_TLS_CERT_ALTNAME_INVALID | |
| 137 | 132 | assert.strictEqual( | |
| 138 | - errors.message('ERR_TLS_CERT_ALTNAME_INVALID', ['altname']), | ||
| 133 | + errors.getMessage('ERR_TLS_CERT_ALTNAME_INVALID', ['altname']), | ||
| 139 | 134 | 'Hostname/IP does not match certificate\'s altnames: altname'); | |
| 140 | 135 | ||
| 141 | 136 | assert.strictEqual( | |
| 142 | - errors.message('ERR_INVALID_PROTOCOL', ['bad protocol', 'http']), | ||
| 137 | + errors.getMessage('ERR_INVALID_PROTOCOL', ['bad protocol', 'http']), | ||
| 143 | 138 | 'Protocol "bad protocol" not supported. Expected "http"' | |
| 144 | 139 | ); | |
| 145 | 140 | ||
| 146 | 141 | assert.strictEqual( | |
| 147 | - errors.message('ERR_HTTP_HEADERS_SENT', ['render']), | ||
| 142 | + errors.getMessage('ERR_HTTP_HEADERS_SENT', ['render']), | ||
| 148 | 143 | 'Cannot render headers after they are sent to the client' | |
| 149 | 144 | ); | |
| 150 | 145 | ||
| 151 | 146 | assert.strictEqual( | |
| 152 | - errors.message('ERR_INVALID_DOMAIN_NAME'), | ||
| 147 | + errors.getMessage('ERR_INVALID_DOMAIN_NAME', []), | ||
| 153 | 148 | 'Unable to determine the domain name' | |
| 154 | 149 | ); | |
| 155 | 150 | ||
| 156 | 151 | assert.strictEqual( | |
| 157 | - errors.message('ERR_INVALID_HTTP_TOKEN', ['Method', 'foo']), | ||
| 152 | + errors.getMessage('ERR_INVALID_HTTP_TOKEN', ['Method', 'foo']), | ||
| 158 | 153 | 'Method must be a valid HTTP token ["foo"]' | |
| 159 | 154 | ); | |
| 160 | 155 | ||
| 161 | 156 | assert.strictEqual( | |
| 162 | - errors.message('ERR_OUT_OF_RANGE', ['A', 'some values', 'B']), | ||
| 157 | + errors.getMessage('ERR_OUT_OF_RANGE', ['A', 'some values', 'B']), | ||
| 163 | 158 | 'The value of "A" is out of range. It must be some values. Received B' | |
| 164 | 159 | ); | |
| 165 | 160 | ||
| 166 | 161 | assert.strictEqual( | |
| 167 | - errors.message('ERR_UNESCAPED_CHARACTERS', ['Request path']), | ||
| 162 | + errors.getMessage('ERR_UNESCAPED_CHARACTERS', ['Request path']), | ||
| 168 | 163 | 'Request path contains unescaped characters' | |
| 169 | 164 | ); | |
| 170 | 165 | ||
| 171 | 166 | // Test ERR_DNS_SET_SERVERS_FAILED | |
| 172 | 167 | assert.strictEqual( | |
| 173 | - errors.message('ERR_DNS_SET_SERVERS_FAILED', ['err', 'servers']), | ||
| 168 | + errors.getMessage('ERR_DNS_SET_SERVERS_FAILED', ['err', 'servers']), | ||
| 174 | 169 | 'c-ares failed to set servers: "err" [servers]'); | |
| 175 | 170 | ||
| 176 | 171 | // Test ERR_ENCODING_NOT_SUPPORTED | |
| 177 | 172 | assert.strictEqual( | |
| 178 | - errors.message('ERR_ENCODING_NOT_SUPPORTED', ['enc']), | ||
| 173 | + errors.getMessage('ERR_ENCODING_NOT_SUPPORTED', ['enc']), | ||
| 179 | 174 | 'The "enc" encoding is not supported'); | |
| 180 | 175 | ||
| 181 | 176 | // Test error messages for async_hooks | |
| 182 | 177 | assert.strictEqual( | |
| 183 | - errors.message('ERR_ASYNC_CALLBACK', ['init']), | ||
| 178 | + errors.getMessage('ERR_ASYNC_CALLBACK', ['init']), | ||
| 184 | 179 | 'init must be a function'); | |
| 185 | 180 | assert.strictEqual( | |
| 186 | - errors.message('ERR_ASYNC_TYPE', [{}]), | ||
| 181 | + errors.getMessage('ERR_ASYNC_TYPE', [{}]), | ||
| 187 | 182 | 'Invalid name for async "type": [object Object]'); | |
| 188 | 183 | assert.strictEqual( | |
| 189 | - errors.message('ERR_INVALID_ASYNC_ID', ['asyncId', undefined]), | ||
| 184 | + errors.getMessage('ERR_INVALID_ASYNC_ID', ['asyncId', undefined]), | ||
| 190 | 185 | 'Invalid asyncId value: undefined'); | |
| 191 | 186 | ||
| 192 | 187 | { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments