@lvce-editor/json-rpc 8.1.0 → 8.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +32 -13
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -24,10 +24,12 @@ const remove = id => {
|
|
|
24
24
|
delete callbacks[id];
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return
|
|
30
|
-
|
|
27
|
+
const create$3 = (() => {
|
|
28
|
+
let id = 0;
|
|
29
|
+
return () => {
|
|
30
|
+
return ++id;
|
|
31
|
+
};
|
|
32
|
+
})();
|
|
31
33
|
|
|
32
34
|
const registerPromise = () => {
|
|
33
35
|
const id = create$3();
|
|
@@ -113,7 +115,10 @@ const constructError = (message, type, name) => {
|
|
|
113
115
|
if (ErrorConstructor === Error) {
|
|
114
116
|
const error = new Error(message);
|
|
115
117
|
if (name && name !== 'VError') {
|
|
116
|
-
error
|
|
118
|
+
Object.defineProperty(error, 'name', {
|
|
119
|
+
configurable: true,
|
|
120
|
+
value: name
|
|
121
|
+
});
|
|
117
122
|
}
|
|
118
123
|
return error;
|
|
119
124
|
}
|
|
@@ -151,31 +156,45 @@ const getParentStack = error => {
|
|
|
151
156
|
const MethodNotFound = -32601;
|
|
152
157
|
const Custom = -32001;
|
|
153
158
|
|
|
159
|
+
const setStack = (error, stack) => {
|
|
160
|
+
const descriptor = Object.getOwnPropertyDescriptor(error, 'stack');
|
|
161
|
+
if (descriptor) {
|
|
162
|
+
if (!descriptor.configurable && !descriptor.writable) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if (!descriptor.configurable && descriptor.writable) {
|
|
166
|
+
error.stack = stack;
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
Object.defineProperty(error, 'stack', {
|
|
171
|
+
configurable: true,
|
|
172
|
+
value: stack,
|
|
173
|
+
writable: true
|
|
174
|
+
});
|
|
175
|
+
};
|
|
154
176
|
const restoreExistingError = (error, currentStack) => {
|
|
155
177
|
if (typeof error.stack === 'string') {
|
|
156
|
-
error
|
|
178
|
+
setStack(error, `${error.stack}${NewLine}${currentStack}`);
|
|
157
179
|
}
|
|
158
180
|
return error;
|
|
159
181
|
};
|
|
160
182
|
const restoreMethodNotFoundError = (error, currentStack) => {
|
|
161
183
|
const restoredError = new JsonRpcError(error.message);
|
|
162
184
|
const parentStack = getParentStack(error);
|
|
163
|
-
restoredError
|
|
185
|
+
setStack(restoredError, `${parentStack}${NewLine}${currentStack}`);
|
|
164
186
|
return restoredError;
|
|
165
187
|
};
|
|
166
188
|
const restoreStackFromData = (restoredError, error, currentStack) => {
|
|
167
189
|
if (error.data.stack && error.data.type && error.message) {
|
|
168
|
-
restoredError
|
|
190
|
+
setStack(restoredError, `${error.data.type}: ${error.message}${NewLine}${error.data.stack}${NewLine}${currentStack}`);
|
|
169
191
|
return;
|
|
170
192
|
}
|
|
171
193
|
if (error.data.stack) {
|
|
172
|
-
restoredError
|
|
194
|
+
setStack(restoredError, error.data.stack);
|
|
173
195
|
}
|
|
174
196
|
};
|
|
175
197
|
const applyDataProperties = (restoredError, error) => {
|
|
176
|
-
if (!error.data) {
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
198
|
restoreStackFromData(restoredError, error, getCurrentStack());
|
|
180
199
|
if (error.data.codeFrame) {
|
|
181
200
|
// @ts-ignore
|
|
@@ -196,7 +215,7 @@ const applyDirectProperties = (restoredError, error) => {
|
|
|
196
215
|
const indexNewLine = getNewLineIndex(lowerStack);
|
|
197
216
|
const parentStack = getParentStack(error);
|
|
198
217
|
// @ts-ignore
|
|
199
|
-
restoredError
|
|
218
|
+
setStack(restoredError, `${parentStack}${lowerStack.slice(indexNewLine)}`);
|
|
200
219
|
}
|
|
201
220
|
if (error.codeFrame) {
|
|
202
221
|
// @ts-ignore
|