@lvce-editor/json-rpc 5.5.0 → 6.1.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 +29 -10
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -120,6 +120,19 @@ const constructError = (message, type, name) => {
|
|
|
120
120
|
return new ErrorConstructor(message);
|
|
121
121
|
};
|
|
122
122
|
|
|
123
|
+
const joinLines = lines => {
|
|
124
|
+
return lines.join(NewLine);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const splitLines = lines => {
|
|
128
|
+
return lines.split(NewLine);
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const getCurrentStack = () => {
|
|
132
|
+
const currentStack = joinLines(splitLines(new Error().stack || '').slice(2));
|
|
133
|
+
return currentStack;
|
|
134
|
+
};
|
|
135
|
+
|
|
123
136
|
const getNewLineIndex = (string, startIndex = undefined) => {
|
|
124
137
|
return string.indexOf(NewLine, startIndex);
|
|
125
138
|
};
|
|
@@ -132,22 +145,17 @@ const getParentStack = error => {
|
|
|
132
145
|
return parentStack;
|
|
133
146
|
};
|
|
134
147
|
|
|
135
|
-
const joinLines = lines => {
|
|
136
|
-
return lines.join(NewLine);
|
|
137
|
-
};
|
|
138
|
-
|
|
139
148
|
const MethodNotFound = -32601;
|
|
140
149
|
const Custom = -32001;
|
|
141
150
|
|
|
142
|
-
const splitLines = lines => {
|
|
143
|
-
return lines.split(NewLine);
|
|
144
|
-
};
|
|
145
|
-
|
|
146
151
|
const restoreJsonRpcError = error => {
|
|
152
|
+
const currentStack = getCurrentStack();
|
|
147
153
|
if (error && error instanceof Error) {
|
|
154
|
+
if (typeof error.stack === 'string') {
|
|
155
|
+
error.stack = error.stack + NewLine + currentStack;
|
|
156
|
+
}
|
|
148
157
|
return error;
|
|
149
158
|
}
|
|
150
|
-
const currentStack = joinLines(splitLines(new Error().stack || '').slice(1));
|
|
151
159
|
if (error && error.code && error.code === MethodNotFound) {
|
|
152
160
|
const restoredError = new JsonRpcError(error.message);
|
|
153
161
|
const parentStack = getParentStack(error);
|
|
@@ -234,6 +242,17 @@ const getErrorType = prettyError => {
|
|
|
234
242
|
return undefined;
|
|
235
243
|
};
|
|
236
244
|
|
|
245
|
+
const isAlreadyStack = line => {
|
|
246
|
+
return line.trim().startsWith('at ');
|
|
247
|
+
};
|
|
248
|
+
const getStack = prettyError => {
|
|
249
|
+
const stackString = prettyError.stack || '';
|
|
250
|
+
const newLineIndex = stackString.indexOf('\n');
|
|
251
|
+
if (newLineIndex !== -1 && !isAlreadyStack(stackString.slice(0, newLineIndex))) {
|
|
252
|
+
return stackString.slice(newLineIndex + 1);
|
|
253
|
+
}
|
|
254
|
+
return stackString;
|
|
255
|
+
};
|
|
237
256
|
const getErrorProperty = (error, prettyError) => {
|
|
238
257
|
if (error && error.code === E_COMMAND_NOT_FOUND) {
|
|
239
258
|
return {
|
|
@@ -246,7 +265,7 @@ const getErrorProperty = (error, prettyError) => {
|
|
|
246
265
|
code: Custom,
|
|
247
266
|
message: prettyError.message,
|
|
248
267
|
data: {
|
|
249
|
-
stack: prettyError
|
|
268
|
+
stack: getStack(prettyError),
|
|
250
269
|
codeFrame: prettyError.codeFrame,
|
|
251
270
|
type: getErrorType(prettyError),
|
|
252
271
|
code: prettyError.code,
|