@lvce-editor/auth-worker 3.5.1 → 3.6.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/authWorkerMain.js +86 -45
- package/package.json +1 -1
package/dist/authWorkerMain.js
CHANGED
|
@@ -478,7 +478,10 @@ const constructError = (message, type, name) => {
|
|
|
478
478
|
if (ErrorConstructor === Error) {
|
|
479
479
|
const error = new Error(message);
|
|
480
480
|
if (name && name !== 'VError') {
|
|
481
|
-
error
|
|
481
|
+
Object.defineProperty(error, 'name', {
|
|
482
|
+
configurable: true,
|
|
483
|
+
value: name
|
|
484
|
+
});
|
|
482
485
|
}
|
|
483
486
|
return error;
|
|
484
487
|
}
|
|
@@ -495,8 +498,10 @@ const getCurrentStack = () => {
|
|
|
495
498
|
const currentStack = joinLines(splitLines(new Error().stack || '').slice(stackLinesToSkip));
|
|
496
499
|
return currentStack;
|
|
497
500
|
};
|
|
498
|
-
const getNewLineIndex = (string, startIndex
|
|
499
|
-
|
|
501
|
+
const getNewLineIndex = (string, startIndex) => {
|
|
502
|
+
{
|
|
503
|
+
return string.indexOf(NewLine);
|
|
504
|
+
}
|
|
500
505
|
};
|
|
501
506
|
const getParentStack = error => {
|
|
502
507
|
let parentStack = error.stack || error.data || error.message || '';
|
|
@@ -507,55 +512,91 @@ const getParentStack = error => {
|
|
|
507
512
|
};
|
|
508
513
|
const MethodNotFound = -32601;
|
|
509
514
|
const Custom = -32001;
|
|
515
|
+
const setStack = (error, stack) => {
|
|
516
|
+
const descriptor = Object.getOwnPropertyDescriptor(error, 'stack');
|
|
517
|
+
if (descriptor) {
|
|
518
|
+
if (!descriptor.configurable && !descriptor.writable) {
|
|
519
|
+
return;
|
|
520
|
+
}
|
|
521
|
+
if (!descriptor.configurable && descriptor.writable) {
|
|
522
|
+
error.stack = stack;
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
Object.defineProperty(error, 'stack', {
|
|
527
|
+
configurable: true,
|
|
528
|
+
value: stack,
|
|
529
|
+
writable: true
|
|
530
|
+
});
|
|
531
|
+
};
|
|
532
|
+
const restoreExistingError = (error, currentStack) => {
|
|
533
|
+
if (typeof error.stack === 'string') {
|
|
534
|
+
setStack(error, `${error.stack}${NewLine}${currentStack}`);
|
|
535
|
+
}
|
|
536
|
+
return error;
|
|
537
|
+
};
|
|
538
|
+
const restoreMethodNotFoundError = (error, currentStack) => {
|
|
539
|
+
const restoredError = new JsonRpcError(error.message);
|
|
540
|
+
const parentStack = getParentStack(error);
|
|
541
|
+
setStack(restoredError, `${parentStack}${NewLine}${currentStack}`);
|
|
542
|
+
return restoredError;
|
|
543
|
+
};
|
|
544
|
+
const restoreStackFromData = (restoredError, error, currentStack) => {
|
|
545
|
+
if (error.data.stack && error.data.type && error.message) {
|
|
546
|
+
setStack(restoredError, `${error.data.type}: ${error.message}${NewLine}${error.data.stack}${NewLine}${currentStack}`);
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
549
|
+
if (error.data.stack) {
|
|
550
|
+
setStack(restoredError, error.data.stack);
|
|
551
|
+
}
|
|
552
|
+
};
|
|
553
|
+
const applyDataProperties = (restoredError, error) => {
|
|
554
|
+
restoreStackFromData(restoredError, error, getCurrentStack());
|
|
555
|
+
if (error.data.codeFrame) {
|
|
556
|
+
// @ts-ignore
|
|
557
|
+
restoredError.codeFrame = error.data.codeFrame;
|
|
558
|
+
}
|
|
559
|
+
if (error.data.code) {
|
|
560
|
+
// @ts-ignore
|
|
561
|
+
restoredError.code = error.data.code;
|
|
562
|
+
}
|
|
563
|
+
if (error.data.type) {
|
|
564
|
+
// @ts-ignore
|
|
565
|
+
restoredError.name = error.data.type;
|
|
566
|
+
}
|
|
567
|
+
};
|
|
568
|
+
const applyDirectProperties = (restoredError, error) => {
|
|
569
|
+
if (error.stack) {
|
|
570
|
+
const lowerStack = restoredError.stack || '';
|
|
571
|
+
const indexNewLine = getNewLineIndex(lowerStack);
|
|
572
|
+
const parentStack = getParentStack(error);
|
|
573
|
+
// @ts-ignore
|
|
574
|
+
setStack(restoredError, `${parentStack}${lowerStack.slice(indexNewLine)}`);
|
|
575
|
+
}
|
|
576
|
+
if (error.codeFrame) {
|
|
577
|
+
// @ts-ignore
|
|
578
|
+
restoredError.codeFrame = error.codeFrame;
|
|
579
|
+
}
|
|
580
|
+
};
|
|
581
|
+
const restoreMessageError = (error, _currentStack) => {
|
|
582
|
+
const restoredError = constructError(error.message, error.type, error.name);
|
|
583
|
+
if (error.data) {
|
|
584
|
+
applyDataProperties(restoredError, error);
|
|
585
|
+
} else {
|
|
586
|
+
applyDirectProperties(restoredError, error);
|
|
587
|
+
}
|
|
588
|
+
return restoredError;
|
|
589
|
+
};
|
|
510
590
|
const restoreJsonRpcError = error => {
|
|
511
591
|
const currentStack = getCurrentStack();
|
|
512
592
|
if (error && error instanceof Error) {
|
|
513
|
-
|
|
514
|
-
error.stack = error.stack + NewLine + currentStack;
|
|
515
|
-
}
|
|
516
|
-
return error;
|
|
593
|
+
return restoreExistingError(error, currentStack);
|
|
517
594
|
}
|
|
518
595
|
if (error && error.code && error.code === MethodNotFound) {
|
|
519
|
-
|
|
520
|
-
const parentStack = getParentStack(error);
|
|
521
|
-
restoredError.stack = parentStack + NewLine + currentStack;
|
|
522
|
-
return restoredError;
|
|
596
|
+
return restoreMethodNotFoundError(error, currentStack);
|
|
523
597
|
}
|
|
524
598
|
if (error && error.message) {
|
|
525
|
-
|
|
526
|
-
if (error.data) {
|
|
527
|
-
if (error.data.stack && error.data.type && error.message) {
|
|
528
|
-
restoredError.stack = error.data.type + ': ' + error.message + NewLine + error.data.stack + NewLine + currentStack;
|
|
529
|
-
} else if (error.data.stack) {
|
|
530
|
-
restoredError.stack = error.data.stack;
|
|
531
|
-
}
|
|
532
|
-
if (error.data.codeFrame) {
|
|
533
|
-
// @ts-ignore
|
|
534
|
-
restoredError.codeFrame = error.data.codeFrame;
|
|
535
|
-
}
|
|
536
|
-
if (error.data.code) {
|
|
537
|
-
// @ts-ignore
|
|
538
|
-
restoredError.code = error.data.code;
|
|
539
|
-
}
|
|
540
|
-
if (error.data.type) {
|
|
541
|
-
// @ts-ignore
|
|
542
|
-
restoredError.name = error.data.type;
|
|
543
|
-
}
|
|
544
|
-
} else {
|
|
545
|
-
if (error.stack) {
|
|
546
|
-
const lowerStack = restoredError.stack || '';
|
|
547
|
-
// @ts-ignore
|
|
548
|
-
const indexNewLine = getNewLineIndex(lowerStack);
|
|
549
|
-
const parentStack = getParentStack(error);
|
|
550
|
-
// @ts-ignore
|
|
551
|
-
restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
|
|
552
|
-
}
|
|
553
|
-
if (error.codeFrame) {
|
|
554
|
-
// @ts-ignore
|
|
555
|
-
restoredError.codeFrame = error.codeFrame;
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
return restoredError;
|
|
599
|
+
return restoreMessageError(error);
|
|
559
600
|
}
|
|
560
601
|
if (typeof error === 'string') {
|
|
561
602
|
return new Error(`JsonRpc Error: ${error}`);
|