@@ -17,7 +17,13 @@ const { kMaxLength } = process.binding('buffer'); |
17 | 17 | const { defineProperty } = Object; |
18 | 18 |
|
19 | 19 | // Lazily loaded |
20 | | -var util = null; |
| 20 | +var util_ = null; |
| 21 | +function lazyUtil() { |
| 22 | + if (!util_) { |
| 23 | + util_ = require('util'); |
| 24 | + } |
| 25 | + return util_; |
| 26 | +} |
21 | 27 |
|
22 | 28 | function makeNodeError(Base) { |
23 | 29 | return class NodeError extends Base { |
@@ -68,11 +74,11 @@ class AssertionError extends Error { |
68 | 74 | if (message) { |
69 | 75 | super(message); |
70 | 76 | } else { |
| 77 | + const util = lazyUtil(); |
71 | 78 | if (actual && actual.stack && actual instanceof Error) |
72 | 79 | actual = `${actual.name}: ${actual.message}`; |
73 | 80 | if (expected && expected.stack && expected instanceof Error) |
74 | 81 | expected = `${expected.name}: ${expected.message}`; |
75 | | - if (util === null) util = require('util'); |
76 | 82 | super(`${util.inspect(actual).slice(0, 128)} ` + |
77 | 83 | `${operator} ${util.inspect(expected).slice(0, 128)}`); |
78 | 84 | } |
@@ -107,7 +113,7 @@ function message(key, args) { |
107 | 113 | if (typeof msg === 'function') { |
108 | 114 | fmt = msg; |
109 | 115 | } else { |
110 | | - if (util === null) util = require('util'); |
| 116 | + const util = lazyUtil(); |
111 | 117 | fmt = util.format; |
112 | 118 | if (args === undefined || args.length === 0) |
113 | 119 | return msg; |
@@ -263,8 +269,14 @@ E('ERR_INSPECTOR_CLOSED', 'Session was closed'); |
263 | 269 | E('ERR_INSPECTOR_NOT_AVAILABLE', 'Inspector is not available'); |
264 | 270 | E('ERR_INSPECTOR_NOT_CONNECTED', 'Session is not connected'); |
265 | 271 | E('ERR_INVALID_ARG_TYPE', invalidArgType); |
266 | | -E('ERR_INVALID_ARG_VALUE', (name, value) => |
267 | | - `The value "${String(value)}" is invalid for argument "${name}"`); |
| 272 | +E('ERR_INVALID_ARG_VALUE', (name, value, reason = 'is invalid') => { |
| 273 | + const util = lazyUtil(); |
| 274 | + let inspected = util.inspect(value); |
| 275 | + if (inspected.length > 128) { |
| 276 | + inspected = inspected.slice(0, 128) + '...'; |
| 277 | + } |
| 278 | + return `The argument '${name}' ${reason}. Received ${inspected}`; |
| 279 | +}), |
268 | 280 | E('ERR_INVALID_ARRAY_LENGTH', |
269 | 281 | (name, len, actual) => { |
270 | 282 | internalAssert(typeof actual === 'number', 'actual must be a number'); |
|