@lvce-editor/extension-management-worker 4.32.0 → 4.34.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.
@@ -151,7 +151,6 @@ const walkValue = (value, transferrables, isTransferrable) => {
151
151
  for (const property of Object.values(value)) {
152
152
  walkValue(property, transferrables, isTransferrable);
153
153
  }
154
- return;
155
154
  }
156
155
  };
157
156
  const getTransferrables = value => {
@@ -305,7 +304,14 @@ class IpcError extends VError {
305
304
  const cause = new Error(message);
306
305
  // @ts-ignore
307
306
  cause.code = code;
308
- cause.stack = stack;
307
+ if (stack) {
308
+ Object.defineProperty(cause, 'stack', {
309
+ configurable: true,
310
+ enumerable: false,
311
+ value: stack,
312
+ writable: true
313
+ });
314
+ }
309
315
  super(cause, betterMessage);
310
316
  } else {
311
317
  super(betterMessage);
@@ -655,7 +661,10 @@ const constructError = (message, type, name) => {
655
661
  if (ErrorConstructor === Error) {
656
662
  const error = new Error(message);
657
663
  if (name && name !== 'VError') {
658
- error.name = name;
664
+ Object.defineProperty(error, 'name', {
665
+ configurable: true,
666
+ value: name
667
+ });
659
668
  }
660
669
  return error;
661
670
  }
@@ -672,8 +681,10 @@ const getCurrentStack = () => {
672
681
  const currentStack = joinLines(splitLines(new Error().stack || '').slice(stackLinesToSkip));
673
682
  return currentStack;
674
683
  };
675
- const getNewLineIndex = (string, startIndex = undefined) => {
676
- return string.indexOf(NewLine$1, startIndex);
684
+ const getNewLineIndex = (string, startIndex) => {
685
+ {
686
+ return string.indexOf(NewLine$1);
687
+ }
677
688
  };
678
689
  const getParentStack = error => {
679
690
  let parentStack = error.stack || error.data || error.message || '';
@@ -684,55 +695,91 @@ const getParentStack = error => {
684
695
  };
685
696
  const MethodNotFound = -32601;
686
697
  const Custom = -32001;
698
+ const setStack = (error, stack) => {
699
+ const descriptor = Object.getOwnPropertyDescriptor(error, 'stack');
700
+ if (descriptor) {
701
+ if (!descriptor.configurable && !descriptor.writable) {
702
+ return;
703
+ }
704
+ if (!descriptor.configurable && descriptor.writable) {
705
+ error.stack = stack;
706
+ return;
707
+ }
708
+ }
709
+ Object.defineProperty(error, 'stack', {
710
+ configurable: true,
711
+ value: stack,
712
+ writable: true
713
+ });
714
+ };
715
+ const restoreExistingError = (error, currentStack) => {
716
+ if (typeof error.stack === 'string') {
717
+ setStack(error, `${error.stack}${NewLine$1}${currentStack}`);
718
+ }
719
+ return error;
720
+ };
721
+ const restoreMethodNotFoundError = (error, currentStack) => {
722
+ const restoredError = new JsonRpcError(error.message);
723
+ const parentStack = getParentStack(error);
724
+ setStack(restoredError, `${parentStack}${NewLine$1}${currentStack}`);
725
+ return restoredError;
726
+ };
727
+ const restoreStackFromData = (restoredError, error, currentStack) => {
728
+ if (error.data.stack && error.data.type && error.message) {
729
+ setStack(restoredError, `${error.data.type}: ${error.message}${NewLine$1}${error.data.stack}${NewLine$1}${currentStack}`);
730
+ return;
731
+ }
732
+ if (error.data.stack) {
733
+ setStack(restoredError, error.data.stack);
734
+ }
735
+ };
736
+ const applyDataProperties = (restoredError, error) => {
737
+ restoreStackFromData(restoredError, error, getCurrentStack());
738
+ if (error.data.codeFrame) {
739
+ // @ts-ignore
740
+ restoredError.codeFrame = error.data.codeFrame;
741
+ }
742
+ if (error.data.code) {
743
+ // @ts-ignore
744
+ restoredError.code = error.data.code;
745
+ }
746
+ if (error.data.type) {
747
+ // @ts-ignore
748
+ restoredError.name = error.data.type;
749
+ }
750
+ };
751
+ const applyDirectProperties = (restoredError, error) => {
752
+ if (error.stack) {
753
+ const lowerStack = restoredError.stack || '';
754
+ const indexNewLine = getNewLineIndex(lowerStack);
755
+ const parentStack = getParentStack(error);
756
+ // @ts-ignore
757
+ setStack(restoredError, `${parentStack}${lowerStack.slice(indexNewLine)}`);
758
+ }
759
+ if (error.codeFrame) {
760
+ // @ts-ignore
761
+ restoredError.codeFrame = error.codeFrame;
762
+ }
763
+ };
764
+ const restoreMessageError = (error, _currentStack) => {
765
+ const restoredError = constructError(error.message, error.type, error.name);
766
+ if (error.data) {
767
+ applyDataProperties(restoredError, error);
768
+ } else {
769
+ applyDirectProperties(restoredError, error);
770
+ }
771
+ return restoredError;
772
+ };
687
773
  const restoreJsonRpcError = error => {
688
774
  const currentStack = getCurrentStack();
689
775
  if (error && error instanceof Error) {
690
- if (typeof error.stack === 'string') {
691
- error.stack = error.stack + NewLine$1 + currentStack;
692
- }
693
- return error;
776
+ return restoreExistingError(error, currentStack);
694
777
  }
695
778
  if (error && error.code && error.code === MethodNotFound) {
696
- const restoredError = new JsonRpcError(error.message);
697
- const parentStack = getParentStack(error);
698
- restoredError.stack = parentStack + NewLine$1 + currentStack;
699
- return restoredError;
779
+ return restoreMethodNotFoundError(error, currentStack);
700
780
  }
701
781
  if (error && error.message) {
702
- const restoredError = constructError(error.message, error.type, error.name);
703
- if (error.data) {
704
- if (error.data.stack && error.data.type && error.message) {
705
- restoredError.stack = error.data.type + ': ' + error.message + NewLine$1 + error.data.stack + NewLine$1 + currentStack;
706
- } else if (error.data.stack) {
707
- restoredError.stack = error.data.stack;
708
- }
709
- if (error.data.codeFrame) {
710
- // @ts-ignore
711
- restoredError.codeFrame = error.data.codeFrame;
712
- }
713
- if (error.data.code) {
714
- // @ts-ignore
715
- restoredError.code = error.data.code;
716
- }
717
- if (error.data.type) {
718
- // @ts-ignore
719
- restoredError.name = error.data.type;
720
- }
721
- } else {
722
- if (error.stack) {
723
- const lowerStack = restoredError.stack || '';
724
- // @ts-ignore
725
- const indexNewLine = getNewLineIndex(lowerStack);
726
- const parentStack = getParentStack(error);
727
- // @ts-ignore
728
- restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
729
- }
730
- if (error.codeFrame) {
731
- // @ts-ignore
732
- restoredError.codeFrame = error.codeFrame;
733
- }
734
- }
735
- return restoredError;
782
+ return restoreMessageError(error);
736
783
  }
737
784
  if (typeof error === 'string') {
738
785
  return new Error(`JsonRpc Error: ${error}`);
@@ -1139,9 +1186,14 @@ const create$5 = async ({
1139
1186
  }) => {
1140
1187
  // TODO create a commandMap per rpc instance
1141
1188
  register(commandMap);
1142
- const rawIpc = await IpcParentWithWebSocket$1.create({
1143
- webSocket
1144
- });
1189
+ let rawIpc;
1190
+ try {
1191
+ rawIpc = await IpcParentWithWebSocket$1.create({
1192
+ webSocket
1193
+ });
1194
+ } catch (error) {
1195
+ throw new VError(error, 'Failed to create rpc connection');
1196
+ }
1145
1197
  const ipc = IpcParentWithWebSocket$1.wrap(rawIpc);
1146
1198
  handleIpc(ipc);
1147
1199
  const rpc = createRpc(ipc);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-management-worker",
3
- "version": "4.32.0",
3
+ "version": "4.34.0",
4
4
  "description": "Webworker for the Extension Management functionality in Lvce Editor.",
5
5
  "keywords": [
6
6
  "web-worker"