@jsenv/plugin-supervisor 1.3.3 → 1.3.5

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.
@@ -9,6 +9,7 @@ window.__supervisor__ = (() => {
9
9
  reloadSupervisedScript: notImplemented,
10
10
  getDocumentExecutionResult: notImplemented
11
11
  };
12
+ const isWebkitOrSafari = typeof window.webkitConvertPointFromNodeToPage === "function";
12
13
  const executionResults = {};
13
14
  let documentExecutionStartTime;
14
15
  try {
@@ -205,7 +206,7 @@ window.__supervisor__ = (() => {
205
206
  error
206
207
  };
207
208
  };
208
- const isWebkitOrSafari = typeof window.webkitConvertPointFromNodeToPage === "function";
209
+
209
210
  // https://twitter.com/damienmaillard/status/1554752482273787906
210
211
  const prepareJsModuleExecutionWithDynamicImport = src => {
211
212
  const urlObject = new URL(src, window.location);
@@ -456,15 +457,25 @@ window.__supervisor__ = (() => {
456
457
  } = {}) => {
457
458
  const exception = {
458
459
  reason,
460
+ isException: true,
459
461
  isError: false,
460
462
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/throw
461
463
  reportedBy,
462
464
  code: null,
465
+ name: null,
463
466
  message: null,
464
- stack: null,
465
- stackFormatIsV8: null,
467
+ stack: "",
468
+ // the stack v8 format
466
469
  stackSourcemapped: null,
467
- originalStack: null,
470
+ stackOriginal: "",
471
+ // the stack from runtime, not normalized to v8
472
+ stackTrace: "",
473
+ // the stack trace (without error name and message)
474
+ withServerUrls: {
475
+ message: "",
476
+ stackTrace: "",
477
+ stack: ""
478
+ },
468
479
  meta: null,
469
480
  site: {
470
481
  isInline: null,
@@ -489,19 +500,20 @@ window.__supervisor__ = (() => {
489
500
  }
490
501
  if (reason instanceof Error) {
491
502
  const error = reason;
492
- let message = error.message;
493
503
  exception.isError = true;
494
- if (Error.captureStackTrace) {
504
+ exception.name = error.name || "Error";
505
+ exception.message = error.message || "";
506
+ if (Error.captureStackTrace &&
507
+ // captureStackTrace exists on webkit but error.stack is not v8
508
+ !isWebkitOrSafari) {
495
509
  // stackTrace formatted by V8
496
- exception.message = message;
497
- exception.stack = getErrorStackWithoutErrorMessage(error);
498
- exception.stackFormatIsV8 = true;
499
510
  exception.stackSourcemapped = true;
500
- } else {
501
- exception.message = message;
502
- exception.stack = error.stack ? " ".concat(error.stack) : null;
503
- exception.stackFormatIsV8 = false;
511
+ exception.stack = error.stack;
512
+ exception.stackTrace = getErrorStackTrace(error);
513
+ } else if (error.stack) {
504
514
  exception.stackSourcemapped = false;
515
+ exception.stackTrace = error.stack;
516
+ exception.stack = stringifyStack(exception);
505
517
  }
506
518
  if (error.reportedBy) {
507
519
  exception.reportedBy = error.reportedBy;
@@ -513,21 +525,21 @@ window.__supervisor__ = (() => {
513
525
  }
514
526
  {
515
527
  // chrome
516
- if (message.includes("does not provide an export named")) {
528
+ if (error.message.includes("does not provide an export named")) {
517
529
  exception.code = DYNAMIC_IMPORT_EXPORT_MISSING;
518
530
  return;
519
531
  }
520
532
  // firefox
521
- if (message.startsWith("import not found:") || message.startsWith("ambiguous indirect export:")) {
533
+ if (error.message.startsWith("import not found:") || error.message.startsWith("ambiguous indirect export:")) {
522
534
  exception.code = DYNAMIC_IMPORT_EXPORT_MISSING;
523
535
  return;
524
536
  }
525
537
  // safari
526
- if (message.startsWith("import binding name")) {
538
+ if (error.message.startsWith("import binding name")) {
527
539
  exception.code = DYNAMIC_IMPORT_EXPORT_MISSING;
528
540
  return;
529
541
  }
530
- if (message.includes("Importing a module script failed")) {
542
+ if (error.message.includes("Importing a module script failed")) {
531
543
  exception.code = DYNAMIC_IMPORT_FETCH_ERROR;
532
544
  return;
533
545
  }
@@ -559,18 +571,6 @@ window.__supervisor__ = (() => {
559
571
  };
560
572
  writeBasicProperties();
561
573
 
562
- // first create a version of the stack with file://
563
- // (and use it to locate exception url+line+column)
564
- if (exception.stack) {
565
- exception.originalStack = exception.stack;
566
- exception.stack = replaceUrls(exception.originalStack, serverUrlSite => {
567
- const fileUrlSite = resolveUrlSite(serverUrlSite);
568
- if (exception.site.url === null) {
569
- Object.assign(exception.site, fileUrlSite);
570
- }
571
- return stringifyUrlSite(fileUrlSite);
572
- });
573
- }
574
574
  // then if it fails, use url+line+column passed
575
575
  if (exception.site.url === null && url) {
576
576
  if (typeof line === "string") {
@@ -590,20 +590,49 @@ window.__supervisor__ = (() => {
590
590
  }
591
591
  Object.assign(exception.site, fileUrlSite);
592
592
  }
593
- exception.text = stringifyMessageAndStack(exception);
593
+ exception.withServerUrls.message = exception.message;
594
+ exception.withServerUrls.stackTrace = exception.stackTrace;
595
+ exception.withServerUrls.stack = exception.stack;
596
+ exception.message = exception.message ? replaceUrls(exception.message, serverUrlSite => {
597
+ const fileUrlSite = resolveUrlSite(serverUrlSite);
598
+ return stringifyUrlSite(fileUrlSite);
599
+ }) : "";
600
+ exception.stackTrace = exception.stackTrace ? replaceUrls(exception.stackTrace, serverUrlSite => {
601
+ const fileUrlSite = resolveUrlSite(serverUrlSite);
602
+ if (exception.site.url === null) {
603
+ Object.assign(exception.site, fileUrlSite);
604
+ }
605
+ return stringifyUrlSite(fileUrlSite);
606
+ }) : "";
607
+ exception.stack = stringifyStack({
608
+ name: exception.name,
609
+ message: exception.message,
610
+ stackTrace: exception.stackTrace
611
+ });
612
+ exception.text = stringifyStack({
613
+ name: exception.name,
614
+ message: exception.message,
615
+ stackTrace: exception.stackTrace
616
+ });
594
617
  return exception;
595
618
  };
596
- const stringifyMessageAndStack = ({
619
+ const stringifyStack = ({
620
+ name,
597
621
  message,
598
- stack
622
+ stackTrace
599
623
  }) => {
600
- if (message && stack) {
601
- return "".concat(message, "\n").concat(stack);
624
+ let stack;
625
+ if (name && message) {
626
+ stack = "".concat(name, ": ").concat(message);
627
+ } else if (message) {
628
+ stack = message;
629
+ } else {
630
+ stack = "";
602
631
  }
603
- if (stack) {
604
- return stack;
632
+ if (stackTrace) {
633
+ stack += "\n".concat(stackTrace);
605
634
  }
606
- return message;
635
+ return stack;
607
636
  };
608
637
  const stringifyUrlSite = ({
609
638
  url,
@@ -653,7 +682,7 @@ window.__supervisor__ = (() => {
653
682
  column
654
683
  };
655
684
  };
656
- const getErrorStackWithoutErrorMessage = error => {
685
+ const getErrorStackTrace = error => {
657
686
  let stack = error.stack;
658
687
  if (!stack) return "";
659
688
  const messageInStack = "".concat(error.name, ": ").concat(error.message);
@@ -771,9 +800,10 @@ window.__supervisor__ = (() => {
771
800
  });
772
801
  return textWithHtmlLinks;
773
802
  };
774
- errorParts.text = stringifyMessageAndStack({
803
+ errorParts.text = stringifyStack({
804
+ name: exceptionInfo.name,
775
805
  message: exceptionInfo.message ? generateClickableText(exceptionInfo.message) : "",
776
- stack: exceptionInfo.stack ? generateClickableText(exceptionInfo.stack) : ""
806
+ stackTrace: exceptionInfo.stackTrace ? generateClickableText(exceptionInfo.stackTrace) : ""
777
807
  });
778
808
  if (exceptionInfo.site.url) {
779
809
  errorParts.errorDetailsPromise = (async () => {
@@ -790,12 +820,14 @@ window.__supervisor__ = (() => {
790
820
  if (!causeInfo) {
791
821
  return null;
792
822
  }
793
- const causeText = causeInfo.code === "NOT_FOUND" ? stringifyMessageAndStack({
823
+ const causeText = causeInfo.code === "NOT_FOUND" ? stringifyStack({
824
+ name: causeInfo.name,
794
825
  message: generateClickableText(causeInfo.reason),
795
- stack: generateClickableText(causeInfo.codeFrame)
796
- }) : stringifyMessageAndStack({
826
+ stackTrace: generateClickableText(causeInfo.codeFrame)
827
+ }) : stringifyStack({
828
+ name: causeInfo.name,
797
829
  message: generateClickableText(causeInfo.stack),
798
- stack: generateClickableText(causeInfo.codeFrame)
830
+ stackTrace: generateClickableText(causeInfo.codeFrame)
799
831
  });
800
832
  return {
801
833
  cause: causeText
@@ -1018,6 +1018,7 @@ const jsenvPluginSupervisor = ({
1018
1018
  const causeInfo = getErrorCauseInfo();
1019
1019
  const body = JSON.stringify(causeInfo ? {
1020
1020
  code: causeInfo.code,
1021
+ name: causeInfo.name,
1021
1022
  message: causeInfo.message,
1022
1023
  reason: causeInfo.reason,
1023
1024
  stack: errorBaseUrl ? "stack mocked for snapshot" : causeInfo.stack,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/plugin-supervisor",
3
- "version": "1.3.3",
3
+ "version": "1.3.5",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -26,10 +26,10 @@
26
26
  "/dist/"
27
27
  ],
28
28
  "dependencies": {
29
- "@jsenv/ast": "5.1.3",
29
+ "@jsenv/ast": "5.1.4",
30
30
  "@jsenv/urls": "2.2.1",
31
- "@jsenv/sourcemap": "1.2.2",
32
- "launch-editor": "2.6.0"
31
+ "@jsenv/sourcemap": "1.2.3",
32
+ "launch-editor": "2.6.1"
33
33
  },
34
34
  "scripts": {
35
35
  "eslint": "npx eslint . --ext=.js,.mjs,.cjs,.html",
@@ -9,6 +9,8 @@ window.__supervisor__ = (() => {
9
9
  reloadSupervisedScript: notImplemented,
10
10
  getDocumentExecutionResult: notImplemented,
11
11
  };
12
+ const isWebkitOrSafari =
13
+ typeof window.webkitConvertPointFromNodeToPage === "function";
12
14
 
13
15
  const executionResults = {};
14
16
  let documentExecutionStartTime;
@@ -192,8 +194,6 @@ window.__supervisor__ = (() => {
192
194
  executions[src] = { isInline: true, start, end, error };
193
195
  };
194
196
 
195
- const isWebkitOrSafari =
196
- typeof window.webkitConvertPointFromNodeToPage === "function";
197
197
  // https://twitter.com/damienmaillard/status/1554752482273787906
198
198
  const prepareJsModuleExecutionWithDynamicImport = (src) => {
199
199
  const urlObject = new URL(src, window.location);
@@ -425,14 +425,21 @@ window.__supervisor__ = (() => {
425
425
  ) => {
426
426
  const exception = {
427
427
  reason,
428
+ isException: true,
428
429
  isError: false, // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/throw
429
430
  reportedBy,
430
431
  code: null,
432
+ name: null,
431
433
  message: null,
432
- stack: null,
433
- stackFormatIsV8: null,
434
+ stack: "", // the stack v8 format
434
435
  stackSourcemapped: null,
435
- originalStack: null,
436
+ stackOriginal: "", // the stack from runtime, not normalized to v8
437
+ stackTrace: "", // the stack trace (without error name and message)
438
+ withServerUrls: {
439
+ message: "",
440
+ stackTrace: "",
441
+ stack: "",
442
+ },
436
443
  meta: null,
437
444
  site: {
438
445
  isInline: null,
@@ -458,20 +465,24 @@ window.__supervisor__ = (() => {
458
465
  }
459
466
  if (reason instanceof Error) {
460
467
  const error = reason;
461
- let message = error.message;
462
468
  exception.isError = true;
463
- if (Error.captureStackTrace) {
469
+ exception.name = error.name || "Error";
470
+ exception.message = error.message || "";
471
+ if (
472
+ Error.captureStackTrace &&
473
+ // captureStackTrace exists on webkit but error.stack is not v8
474
+ !isWebkitOrSafari
475
+ ) {
464
476
  // stackTrace formatted by V8
465
- exception.message = message;
466
- exception.stack = getErrorStackWithoutErrorMessage(error);
467
- exception.stackFormatIsV8 = true;
468
477
  exception.stackSourcemapped = true;
469
- } else {
470
- exception.message = message;
471
- exception.stack = error.stack ? ` ${error.stack}` : null;
472
- exception.stackFormatIsV8 = false;
478
+ exception.stack = error.stack;
479
+ exception.stackTrace = getErrorStackTrace(error);
480
+ } else if (error.stack) {
473
481
  exception.stackSourcemapped = false;
482
+ exception.stackTrace = error.stack;
483
+ exception.stack = stringifyStack(exception);
474
484
  }
485
+
475
486
  if (error.reportedBy) {
476
487
  exception.reportedBy = error.reportedBy;
477
488
  }
@@ -480,24 +491,24 @@ window.__supervisor__ = (() => {
480
491
  }
481
492
  export_missing: {
482
493
  // chrome
483
- if (message.includes("does not provide an export named")) {
494
+ if (error.message.includes("does not provide an export named")) {
484
495
  exception.code = DYNAMIC_IMPORT_EXPORT_MISSING;
485
496
  return;
486
497
  }
487
498
  // firefox
488
499
  if (
489
- message.startsWith("import not found:") ||
490
- message.startsWith("ambiguous indirect export:")
500
+ error.message.startsWith("import not found:") ||
501
+ error.message.startsWith("ambiguous indirect export:")
491
502
  ) {
492
503
  exception.code = DYNAMIC_IMPORT_EXPORT_MISSING;
493
504
  return;
494
505
  }
495
506
  // safari
496
- if (message.startsWith("import binding name")) {
507
+ if (error.message.startsWith("import binding name")) {
497
508
  exception.code = DYNAMIC_IMPORT_EXPORT_MISSING;
498
509
  return;
499
510
  }
500
- if (message.includes("Importing a module script failed")) {
511
+ if (error.message.includes("Importing a module script failed")) {
501
512
  exception.code = DYNAMIC_IMPORT_FETCH_ERROR;
502
513
  return;
503
514
  }
@@ -527,21 +538,6 @@ window.__supervisor__ = (() => {
527
538
  };
528
539
  writeBasicProperties();
529
540
 
530
- // first create a version of the stack with file://
531
- // (and use it to locate exception url+line+column)
532
- if (exception.stack) {
533
- exception.originalStack = exception.stack;
534
- exception.stack = replaceUrls(
535
- exception.originalStack,
536
- (serverUrlSite) => {
537
- const fileUrlSite = resolveUrlSite(serverUrlSite);
538
- if (exception.site.url === null) {
539
- Object.assign(exception.site, fileUrlSite);
540
- }
541
- return stringifyUrlSite(fileUrlSite);
542
- },
543
- );
544
- }
545
541
  // then if it fails, use url+line+column passed
546
542
  if (exception.site.url === null && url) {
547
543
  if (typeof line === "string") {
@@ -560,18 +556,51 @@ window.__supervisor__ = (() => {
560
556
  }
561
557
  Object.assign(exception.site, fileUrlSite);
562
558
  }
563
- exception.text = stringifyMessageAndStack(exception);
559
+
560
+ exception.withServerUrls.message = exception.message;
561
+ exception.withServerUrls.stackTrace = exception.stackTrace;
562
+ exception.withServerUrls.stack = exception.stack;
563
+ exception.message = exception.message
564
+ ? replaceUrls(exception.message, (serverUrlSite) => {
565
+ const fileUrlSite = resolveUrlSite(serverUrlSite);
566
+ return stringifyUrlSite(fileUrlSite);
567
+ })
568
+ : "";
569
+ exception.stackTrace = exception.stackTrace
570
+ ? replaceUrls(exception.stackTrace, (serverUrlSite) => {
571
+ const fileUrlSite = resolveUrlSite(serverUrlSite);
572
+ if (exception.site.url === null) {
573
+ Object.assign(exception.site, fileUrlSite);
574
+ }
575
+ return stringifyUrlSite(fileUrlSite);
576
+ })
577
+ : "";
578
+ exception.stack = stringifyStack({
579
+ name: exception.name,
580
+ message: exception.message,
581
+ stackTrace: exception.stackTrace,
582
+ });
583
+ exception.text = stringifyStack({
584
+ name: exception.name,
585
+ message: exception.message,
586
+ stackTrace: exception.stackTrace,
587
+ });
564
588
  return exception;
565
589
  };
566
590
 
567
- const stringifyMessageAndStack = ({ message, stack }) => {
568
- if (message && stack) {
569
- return `${message}\n${stack}`;
591
+ const stringifyStack = ({ name, message, stackTrace }) => {
592
+ let stack;
593
+ if (name && message) {
594
+ stack = `${name}: ${message}`;
595
+ } else if (message) {
596
+ stack = message;
597
+ } else {
598
+ stack = "";
570
599
  }
571
- if (stack) {
572
- return stack;
600
+ if (stackTrace) {
601
+ stack += `\n${stackTrace}`;
573
602
  }
574
- return message;
603
+ return stack;
575
604
  };
576
605
 
577
606
  const stringifyUrlSite = ({ url, line, column }) => {
@@ -618,7 +647,7 @@ window.__supervisor__ = (() => {
618
647
  };
619
648
  };
620
649
 
621
- const getErrorStackWithoutErrorMessage = (error) => {
650
+ const getErrorStackTrace = (error) => {
622
651
  let stack = error.stack;
623
652
  if (!stack) return "";
624
653
  const messageInStack = `${error.name}: ${error.message}`;
@@ -745,12 +774,13 @@ window.__supervisor__ = (() => {
745
774
  return textWithHtmlLinks;
746
775
  };
747
776
 
748
- errorParts.text = stringifyMessageAndStack({
777
+ errorParts.text = stringifyStack({
778
+ name: exceptionInfo.name,
749
779
  message: exceptionInfo.message
750
780
  ? generateClickableText(exceptionInfo.message)
751
781
  : "",
752
- stack: exceptionInfo.stack
753
- ? generateClickableText(exceptionInfo.stack)
782
+ stackTrace: exceptionInfo.stackTrace
783
+ ? generateClickableText(exceptionInfo.stackTrace)
754
784
  : "",
755
785
  });
756
786
  if (exceptionInfo.site.url) {
@@ -779,13 +809,15 @@ window.__supervisor__ = (() => {
779
809
  }
780
810
  const causeText =
781
811
  causeInfo.code === "NOT_FOUND"
782
- ? stringifyMessageAndStack({
812
+ ? stringifyStack({
813
+ name: causeInfo.name,
783
814
  message: generateClickableText(causeInfo.reason),
784
- stack: generateClickableText(causeInfo.codeFrame),
815
+ stackTrace: generateClickableText(causeInfo.codeFrame),
785
816
  })
786
- : stringifyMessageAndStack({
817
+ : stringifyStack({
818
+ name: causeInfo.name,
787
819
  message: generateClickableText(causeInfo.stack),
788
- stack: generateClickableText(causeInfo.codeFrame),
820
+ stackTrace: generateClickableText(causeInfo.codeFrame),
789
821
  });
790
822
  return {
791
823
  cause: causeText,
@@ -117,6 +117,7 @@ export const jsenvPluginSupervisor = ({
117
117
  causeInfo
118
118
  ? {
119
119
  code: causeInfo.code,
120
+ name: causeInfo.name,
120
121
  message: causeInfo.message,
121
122
  reason: causeInfo.reason,
122
123
  stack: errorBaseUrl