@lvce-editor/file-system-process 5.5.1 → 5.7.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.
Files changed (2) hide show
  1. package/dist/index.js +86 -45
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -821,7 +821,10 @@ const constructError = (message, type, name) => {
821
821
  if (ErrorConstructor === Error) {
822
822
  const error = new Error(message);
823
823
  if (name && name !== 'VError') {
824
- error.name = name;
824
+ Object.defineProperty(error, 'name', {
825
+ configurable: true,
826
+ value: name
827
+ });
825
828
  }
826
829
  return error;
827
830
  }
@@ -838,8 +841,10 @@ const getCurrentStack = () => {
838
841
  const currentStack = joinLines(splitLines(new Error().stack || '').slice(stackLinesToSkip));
839
842
  return currentStack;
840
843
  };
841
- const getNewLineIndex = (string, startIndex = undefined) => {
842
- return string.indexOf(NewLine, startIndex);
844
+ const getNewLineIndex = (string, startIndex) => {
845
+ {
846
+ return string.indexOf(NewLine);
847
+ }
843
848
  };
844
849
  const getParentStack = error => {
845
850
  let parentStack = error.stack || error.data || error.message || '';
@@ -850,55 +855,91 @@ const getParentStack = error => {
850
855
  };
851
856
  const MethodNotFound = -32601;
852
857
  const Custom = -32001;
858
+ const setStack = (error, stack) => {
859
+ const descriptor = Object.getOwnPropertyDescriptor(error, 'stack');
860
+ if (descriptor) {
861
+ if (!descriptor.configurable && !descriptor.writable) {
862
+ return;
863
+ }
864
+ if (!descriptor.configurable && descriptor.writable) {
865
+ error.stack = stack;
866
+ return;
867
+ }
868
+ }
869
+ Object.defineProperty(error, 'stack', {
870
+ configurable: true,
871
+ value: stack,
872
+ writable: true
873
+ });
874
+ };
875
+ const restoreExistingError = (error, currentStack) => {
876
+ if (typeof error.stack === 'string') {
877
+ setStack(error, `${error.stack}${NewLine}${currentStack}`);
878
+ }
879
+ return error;
880
+ };
881
+ const restoreMethodNotFoundError = (error, currentStack) => {
882
+ const restoredError = new JsonRpcError(error.message);
883
+ const parentStack = getParentStack(error);
884
+ setStack(restoredError, `${parentStack}${NewLine}${currentStack}`);
885
+ return restoredError;
886
+ };
887
+ const restoreStackFromData = (restoredError, error, currentStack) => {
888
+ if (error.data.stack && error.data.type && error.message) {
889
+ setStack(restoredError, `${error.data.type}: ${error.message}${NewLine}${error.data.stack}${NewLine}${currentStack}`);
890
+ return;
891
+ }
892
+ if (error.data.stack) {
893
+ setStack(restoredError, error.data.stack);
894
+ }
895
+ };
896
+ const applyDataProperties = (restoredError, error) => {
897
+ restoreStackFromData(restoredError, error, getCurrentStack());
898
+ if (error.data.codeFrame) {
899
+ // @ts-ignore
900
+ restoredError.codeFrame = error.data.codeFrame;
901
+ }
902
+ if (error.data.code) {
903
+ // @ts-ignore
904
+ restoredError.code = error.data.code;
905
+ }
906
+ if (error.data.type) {
907
+ // @ts-ignore
908
+ restoredError.name = error.data.type;
909
+ }
910
+ };
911
+ const applyDirectProperties = (restoredError, error) => {
912
+ if (error.stack) {
913
+ const lowerStack = restoredError.stack || '';
914
+ const indexNewLine = getNewLineIndex(lowerStack);
915
+ const parentStack = getParentStack(error);
916
+ // @ts-ignore
917
+ setStack(restoredError, `${parentStack}${lowerStack.slice(indexNewLine)}`);
918
+ }
919
+ if (error.codeFrame) {
920
+ // @ts-ignore
921
+ restoredError.codeFrame = error.codeFrame;
922
+ }
923
+ };
924
+ const restoreMessageError = (error, _currentStack) => {
925
+ const restoredError = constructError(error.message, error.type, error.name);
926
+ if (error.data) {
927
+ applyDataProperties(restoredError, error);
928
+ } else {
929
+ applyDirectProperties(restoredError, error);
930
+ }
931
+ return restoredError;
932
+ };
853
933
  const restoreJsonRpcError = error => {
854
934
  const currentStack = getCurrentStack();
855
935
  if (error && error instanceof Error) {
856
- if (typeof error.stack === 'string') {
857
- error.stack = error.stack + NewLine + currentStack;
858
- }
859
- return error;
936
+ return restoreExistingError(error, currentStack);
860
937
  }
861
938
  if (error && error.code && error.code === MethodNotFound) {
862
- const restoredError = new JsonRpcError(error.message);
863
- const parentStack = getParentStack(error);
864
- restoredError.stack = parentStack + NewLine + currentStack;
865
- return restoredError;
939
+ return restoreMethodNotFoundError(error, currentStack);
866
940
  }
867
941
  if (error && error.message) {
868
- const restoredError = constructError(error.message, error.type, error.name);
869
- if (error.data) {
870
- if (error.data.stack && error.data.type && error.message) {
871
- restoredError.stack = error.data.type + ': ' + error.message + NewLine + error.data.stack + NewLine + currentStack;
872
- } else if (error.data.stack) {
873
- restoredError.stack = error.data.stack;
874
- }
875
- if (error.data.codeFrame) {
876
- // @ts-ignore
877
- restoredError.codeFrame = error.data.codeFrame;
878
- }
879
- if (error.data.code) {
880
- // @ts-ignore
881
- restoredError.code = error.data.code;
882
- }
883
- if (error.data.type) {
884
- // @ts-ignore
885
- restoredError.name = error.data.type;
886
- }
887
- } else {
888
- if (error.stack) {
889
- const lowerStack = restoredError.stack || '';
890
- // @ts-ignore
891
- const indexNewLine = getNewLineIndex(lowerStack);
892
- const parentStack = getParentStack(error);
893
- // @ts-ignore
894
- restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
895
- }
896
- if (error.codeFrame) {
897
- // @ts-ignore
898
- restoredError.codeFrame = error.codeFrame;
899
- }
900
- }
901
- return restoredError;
942
+ return restoreMessageError(error);
902
943
  }
903
944
  if (typeof error === 'string') {
904
945
  return new Error(`JsonRpc Error: ${error}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/file-system-process",
3
- "version": "5.5.1",
3
+ "version": "5.7.0",
4
4
  "description": "File System Process",
5
5
  "keywords": [
6
6
  "Lvce Editor",
@@ -19,7 +19,7 @@
19
19
  },
20
20
  "dependencies": {
21
21
  "trash": "^10.1.1",
22
- "ws": "^8.21.0"
22
+ "ws": "^8.21.1"
23
23
  },
24
24
  "engines": {
25
25
  "node": ">=24"