|
12 | 12 |
|
13 | 13 | const { Object, Math } = primordials;
|
14 | 14 |
|
15 |
| -const kCode = Symbol('code'); |
16 |
| -const kInfo = Symbol('info'); |
17 | 15 | const messages = new Map();
|
18 | 16 | const codes = {};
|
19 | 17 |
|
@@ -107,76 +105,81 @@ class SystemError extends Error {
|
107 | 105 | writable: true,
|
108 | 106 | configurable: true
|
109 | 107 | });
|
110 |
| - Object.defineProperty(this, kInfo, { |
111 |
| - configurable: false, |
112 |
| - enumerable: false, |
113 |
| - value: context |
114 |
| - }); |
115 |
| - Object.defineProperty(this, kCode, { |
116 |
| - configurable: true, |
117 |
| - enumerable: false, |
118 |
| - value: key, |
119 |
| - writable: true |
120 |
| - }); |
121 | 108 | addCodeToName(this, 'SystemError', key);
|
122 |
| - } |
123 | 109 |
|
124 |
| - get code() { |
125 |
| - return this[kCode]; |
126 |
| - } |
| 110 | + this.code = key; |
127 | 111 |
|
128 |
| - set code(value) { |
129 |
| - Object.defineProperty(this, 'code', { |
130 |
| - configurable: true, |
| 112 | + Object.defineProperty(this, 'info', { |
| 113 | + value: context, |
131 | 114 | enumerable: true,
|
132 |
| - value, |
133 |
| - writable: true |
| 115 | + configurable: true, |
| 116 | + writable: false |
134 | 117 | });
|
135 |
| - } |
136 |
| - |
137 |
| - get info() { |
138 |
| - return this[kInfo]; |
139 |
| - } |
140 | 118 |
|
141 |
| - get errno() { |
142 |
| - return this[kInfo].errno; |
143 |
| - } |
144 |
| - |
145 |
| - set errno(val) { |
146 |
| - this[kInfo].errno = val; |
147 |
| - } |
148 |
| - |
149 |
| - get syscall() { |
150 |
| - return this[kInfo].syscall; |
151 |
| - } |
152 |
| - |
153 |
| - set syscall(val) { |
154 |
| - this[kInfo].syscall = val; |
155 |
| - } |
156 |
| - |
157 |
| - get path() { |
158 |
| - return this[kInfo].path !== undefined ? |
159 |
| - this[kInfo].path.toString() : undefined; |
160 |
| - } |
| 119 | + Object.defineProperty(this, 'errno', { |
| 120 | + get() { |
| 121 | + return context.errno; |
| 122 | + }, |
| 123 | + set: (value) => { |
| 124 | + context.errno = value; |
| 125 | + }, |
| 126 | + enumerable: true, |
| 127 | + configurable: true |
| 128 | + }); |
161 | 129 |
|
162 |
| - set path(val) { |
163 |
| - this[kInfo].path = val ? |
164 |
| - lazyBuffer().from(val.toString()) : undefined; |
165 |
| - } |
| 130 | + Object.defineProperty(this, 'syscall', { |
| 131 | + get() { |
| 132 | + return context.syscall; |
| 133 | + }, |
| 134 | + set: (value) => { |
| 135 | + context.syscall = value; |
| 136 | + }, |
| 137 | + enumerable: true, |
| 138 | + configurable: true |
| 139 | + }); |
166 | 140 |
|
167 |
| - get dest() { |
168 |
| - return this[kInfo].path !== undefined ? |
169 |
| - this[kInfo].dest.toString() : undefined; |
170 |
| - } |
| 141 | + if (context.path !== undefined) { |
| 142 | + Object.defineProperty(this, 'path', { |
| 143 | + get() { |
| 144 | + return context.path != null ? |
| 145 | + context.path.toString() : context.path; |
| 146 | + }, |
| 147 | + set: (value) => { |
| 148 | + context.path = value ? |
| 149 | + lazyBuffer().from(value.toString()) : undefined; |
| 150 | + }, |
| 151 | + enumerable: true, |
| 152 | + configurable: true |
| 153 | + }); |
| 154 | + } |
171 | 155 |
|
172 |
| - set dest(val) { |
173 |
| - this[kInfo].dest = val ? |
174 |
| - lazyBuffer().from(val.toString()) : undefined; |
| 156 | + if (context.dest !== undefined) { |
| 157 | + Object.defineProperty(this, 'dest', { |
| 158 | + get() { |
| 159 | + return context.dest != null ? |
| 160 | + context.dest.toString() : context.dest; |
| 161 | + }, |
| 162 | + set: (value) => { |
| 163 | + context.dest = value ? |
| 164 | + lazyBuffer().from(value.toString()) : undefined; |
| 165 | + }, |
| 166 | + enumerable: true, |
| 167 | + configurable: true |
| 168 | + }); |
| 169 | + } |
175 | 170 | }
|
176 | 171 |
|
177 | 172 | toString() {
|
178 | 173 | return `${this.name} [${this.code}]: ${this.message}`;
|
179 | 174 | }
|
| 175 | + |
| 176 | + [Symbol.for('nodejs.util.inspect.custom')](recurseTimes, ctx) { |
| 177 | + return lazyInternalUtilInspect().inspect(this, { |
| 178 | + ...ctx, |
| 179 | + getters: true, |
| 180 | + customInspect: false |
| 181 | + }); |
| 182 | + } |
180 | 183 | }
|
181 | 184 |
|
182 | 185 | function makeSystemErrorWithCode(key) {
|
@@ -207,19 +210,7 @@ function makeNodeErrorWithCode(Base, key) {
|
207 | 210 | configurable: true
|
208 | 211 | });
|
209 | 212 | addCodeToName(this, super.name, key);
|
210 |
| - } |
211 |
| - |
212 |
| - get code() { |
213 |
| - return key; |
214 |
| - } |
215 |
| - |
216 |
| - set code(value) { |
217 |
| - Object.defineProperty(this, 'code', { |
218 |
| - configurable: true, |
219 |
| - enumerable: true, |
220 |
| - value, |
221 |
| - writable: true |
222 |
| - }); |
| 213 | + this.code = key; |
223 | 214 | }
|
224 | 215 |
|
225 | 216 | toString() {
|
@@ -380,7 +371,6 @@ function uvException(ctx) {
|
380 | 371 | err[prop] = ctx[prop];
|
381 | 372 | }
|
382 | 373 |
|
383 |
| - // TODO(BridgeAR): Show the `code` property as part of the stack. |
384 | 374 | err.code = code;
|
385 | 375 | if (path) {
|
386 | 376 | err.path = path;
|
|
0 commit comments