@lvce-editor/menu-worker 4.10.0 → 4.11.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/menuWorkerMain.js +86 -45
- package/package.json +1 -1
package/dist/menuWorkerMain.js
CHANGED
|
@@ -580,7 +580,10 @@ const constructError = (message, type, name) => {
|
|
|
580
580
|
if (ErrorConstructor === Error) {
|
|
581
581
|
const error = new Error(message);
|
|
582
582
|
if (name && name !== 'VError') {
|
|
583
|
-
error
|
|
583
|
+
Object.defineProperty(error, 'name', {
|
|
584
|
+
configurable: true,
|
|
585
|
+
value: name
|
|
586
|
+
});
|
|
584
587
|
}
|
|
585
588
|
return error;
|
|
586
589
|
}
|
|
@@ -597,8 +600,10 @@ const getCurrentStack = () => {
|
|
|
597
600
|
const currentStack = joinLines(splitLines(new Error().stack || '').slice(stackLinesToSkip));
|
|
598
601
|
return currentStack;
|
|
599
602
|
};
|
|
600
|
-
const getNewLineIndex = (string, startIndex
|
|
601
|
-
|
|
603
|
+
const getNewLineIndex = (string, startIndex) => {
|
|
604
|
+
{
|
|
605
|
+
return string.indexOf(NewLine);
|
|
606
|
+
}
|
|
602
607
|
};
|
|
603
608
|
const getParentStack = error => {
|
|
604
609
|
let parentStack = error.stack || error.data || error.message || '';
|
|
@@ -609,55 +614,91 @@ const getParentStack = error => {
|
|
|
609
614
|
};
|
|
610
615
|
const MethodNotFound = -32601;
|
|
611
616
|
const Custom = -32001;
|
|
617
|
+
const setStack = (error, stack) => {
|
|
618
|
+
const descriptor = Object.getOwnPropertyDescriptor(error, 'stack');
|
|
619
|
+
if (descriptor) {
|
|
620
|
+
if (!descriptor.configurable && !descriptor.writable) {
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
if (!descriptor.configurable && descriptor.writable) {
|
|
624
|
+
error.stack = stack;
|
|
625
|
+
return;
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
Object.defineProperty(error, 'stack', {
|
|
629
|
+
configurable: true,
|
|
630
|
+
value: stack,
|
|
631
|
+
writable: true
|
|
632
|
+
});
|
|
633
|
+
};
|
|
634
|
+
const restoreExistingError = (error, currentStack) => {
|
|
635
|
+
if (typeof error.stack === 'string') {
|
|
636
|
+
setStack(error, `${error.stack}${NewLine}${currentStack}`);
|
|
637
|
+
}
|
|
638
|
+
return error;
|
|
639
|
+
};
|
|
640
|
+
const restoreMethodNotFoundError = (error, currentStack) => {
|
|
641
|
+
const restoredError = new JsonRpcError(error.message);
|
|
642
|
+
const parentStack = getParentStack(error);
|
|
643
|
+
setStack(restoredError, `${parentStack}${NewLine}${currentStack}`);
|
|
644
|
+
return restoredError;
|
|
645
|
+
};
|
|
646
|
+
const restoreStackFromData = (restoredError, error, currentStack) => {
|
|
647
|
+
if (error.data.stack && error.data.type && error.message) {
|
|
648
|
+
setStack(restoredError, `${error.data.type}: ${error.message}${NewLine}${error.data.stack}${NewLine}${currentStack}`);
|
|
649
|
+
return;
|
|
650
|
+
}
|
|
651
|
+
if (error.data.stack) {
|
|
652
|
+
setStack(restoredError, error.data.stack);
|
|
653
|
+
}
|
|
654
|
+
};
|
|
655
|
+
const applyDataProperties = (restoredError, error) => {
|
|
656
|
+
restoreStackFromData(restoredError, error, getCurrentStack());
|
|
657
|
+
if (error.data.codeFrame) {
|
|
658
|
+
// @ts-ignore
|
|
659
|
+
restoredError.codeFrame = error.data.codeFrame;
|
|
660
|
+
}
|
|
661
|
+
if (error.data.code) {
|
|
662
|
+
// @ts-ignore
|
|
663
|
+
restoredError.code = error.data.code;
|
|
664
|
+
}
|
|
665
|
+
if (error.data.type) {
|
|
666
|
+
// @ts-ignore
|
|
667
|
+
restoredError.name = error.data.type;
|
|
668
|
+
}
|
|
669
|
+
};
|
|
670
|
+
const applyDirectProperties = (restoredError, error) => {
|
|
671
|
+
if (error.stack) {
|
|
672
|
+
const lowerStack = restoredError.stack || '';
|
|
673
|
+
const indexNewLine = getNewLineIndex(lowerStack);
|
|
674
|
+
const parentStack = getParentStack(error);
|
|
675
|
+
// @ts-ignore
|
|
676
|
+
setStack(restoredError, `${parentStack}${lowerStack.slice(indexNewLine)}`);
|
|
677
|
+
}
|
|
678
|
+
if (error.codeFrame) {
|
|
679
|
+
// @ts-ignore
|
|
680
|
+
restoredError.codeFrame = error.codeFrame;
|
|
681
|
+
}
|
|
682
|
+
};
|
|
683
|
+
const restoreMessageError = (error, _currentStack) => {
|
|
684
|
+
const restoredError = constructError(error.message, error.type, error.name);
|
|
685
|
+
if (error.data) {
|
|
686
|
+
applyDataProperties(restoredError, error);
|
|
687
|
+
} else {
|
|
688
|
+
applyDirectProperties(restoredError, error);
|
|
689
|
+
}
|
|
690
|
+
return restoredError;
|
|
691
|
+
};
|
|
612
692
|
const restoreJsonRpcError = error => {
|
|
613
693
|
const currentStack = getCurrentStack();
|
|
614
694
|
if (error && error instanceof Error) {
|
|
615
|
-
|
|
616
|
-
error.stack = error.stack + NewLine + currentStack;
|
|
617
|
-
}
|
|
618
|
-
return error;
|
|
695
|
+
return restoreExistingError(error, currentStack);
|
|
619
696
|
}
|
|
620
697
|
if (error && error.code && error.code === MethodNotFound) {
|
|
621
|
-
|
|
622
|
-
const parentStack = getParentStack(error);
|
|
623
|
-
restoredError.stack = parentStack + NewLine + currentStack;
|
|
624
|
-
return restoredError;
|
|
698
|
+
return restoreMethodNotFoundError(error, currentStack);
|
|
625
699
|
}
|
|
626
700
|
if (error && error.message) {
|
|
627
|
-
|
|
628
|
-
if (error.data) {
|
|
629
|
-
if (error.data.stack && error.data.type && error.message) {
|
|
630
|
-
restoredError.stack = error.data.type + ': ' + error.message + NewLine + error.data.stack + NewLine + currentStack;
|
|
631
|
-
} else if (error.data.stack) {
|
|
632
|
-
restoredError.stack = error.data.stack;
|
|
633
|
-
}
|
|
634
|
-
if (error.data.codeFrame) {
|
|
635
|
-
// @ts-ignore
|
|
636
|
-
restoredError.codeFrame = error.data.codeFrame;
|
|
637
|
-
}
|
|
638
|
-
if (error.data.code) {
|
|
639
|
-
// @ts-ignore
|
|
640
|
-
restoredError.code = error.data.code;
|
|
641
|
-
}
|
|
642
|
-
if (error.data.type) {
|
|
643
|
-
// @ts-ignore
|
|
644
|
-
restoredError.name = error.data.type;
|
|
645
|
-
}
|
|
646
|
-
} else {
|
|
647
|
-
if (error.stack) {
|
|
648
|
-
const lowerStack = restoredError.stack || '';
|
|
649
|
-
// @ts-ignore
|
|
650
|
-
const indexNewLine = getNewLineIndex(lowerStack);
|
|
651
|
-
const parentStack = getParentStack(error);
|
|
652
|
-
// @ts-ignore
|
|
653
|
-
restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
|
|
654
|
-
}
|
|
655
|
-
if (error.codeFrame) {
|
|
656
|
-
// @ts-ignore
|
|
657
|
-
restoredError.codeFrame = error.codeFrame;
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
return restoredError;
|
|
701
|
+
return restoreMessageError(error);
|
|
661
702
|
}
|
|
662
703
|
if (typeof error === 'string') {
|
|
663
704
|
return new Error(`JsonRpc Error: ${error}`);
|