@shaper.org/core 1.0.5 → 1.0.7
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/node/index.mjs
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
import { ViteHook } from "./vite-hook";
|
|
2
|
-
import { ViteMessage } from "./vite-message";
|
|
3
2
|
import { IframePostMessageClient } from "../client";
|
|
3
|
+
import { ErrorInfo } from "src/client/iframe-post-message";
|
|
4
4
|
|
|
5
5
|
class ErrorTracker {
|
|
6
6
|
public vHook: ViteHook;
|
|
7
|
-
public viteMessage: ViteMessage;
|
|
8
7
|
private iframeClient: IframePostMessageClient;
|
|
9
8
|
|
|
10
9
|
constructor() {
|
|
11
|
-
this.viteMessage = new ViteMessage();
|
|
12
|
-
|
|
13
10
|
this.vHook = new ViteHook();
|
|
14
|
-
|
|
15
11
|
this.iframeClient = new IframePostMessageClient();
|
|
16
12
|
}
|
|
17
13
|
|
|
@@ -23,7 +19,8 @@ class ErrorTracker {
|
|
|
23
19
|
start() {
|
|
24
20
|
this.handleError();
|
|
25
21
|
this.handleUnhandledrejection();
|
|
26
|
-
this.
|
|
22
|
+
this.handleConsoleInterception();
|
|
23
|
+
this.handleViteError();
|
|
27
24
|
}
|
|
28
25
|
|
|
29
26
|
formatConsoleMessage(args: unknown[]): string {
|
|
@@ -44,7 +41,7 @@ class ErrorTracker {
|
|
|
44
41
|
return texts.map((text) => String(text)).join(" ");
|
|
45
42
|
}
|
|
46
43
|
|
|
47
|
-
|
|
44
|
+
handleConsoleInterception() {
|
|
48
45
|
type LogLevel = keyof typeof originalConsole;
|
|
49
46
|
|
|
50
47
|
const originalConsole = {
|
|
@@ -66,7 +63,7 @@ class ErrorTracker {
|
|
|
66
63
|
if (!message) return;
|
|
67
64
|
|
|
68
65
|
if (logLevel === "error") {
|
|
69
|
-
console.debug("console error", message);
|
|
66
|
+
console.debug("[vite-shaper] console error", message);
|
|
70
67
|
this.iframeClient.sendError({
|
|
71
68
|
errorType: "RUNTIME_ERROR",
|
|
72
69
|
timestamp: Date.now(),
|
|
@@ -78,9 +75,31 @@ class ErrorTracker {
|
|
|
78
75
|
}
|
|
79
76
|
}
|
|
80
77
|
|
|
78
|
+
handleViteError() {
|
|
79
|
+
this.vHook.onError((data) => {
|
|
80
|
+
console.debug("[vite-shaper] vite:error", data);
|
|
81
|
+
|
|
82
|
+
let error: ErrorInfo = {
|
|
83
|
+
errorType: "RUNTIME_ERROR",
|
|
84
|
+
timestamp: Date.now(),
|
|
85
|
+
stack: data.err.message,
|
|
86
|
+
has_blank_screen: this.isBlankScreen(),
|
|
87
|
+
};
|
|
88
|
+
if (data.err.loc) {
|
|
89
|
+
error = {
|
|
90
|
+
...error,
|
|
91
|
+
lineno: data.err.loc.line,
|
|
92
|
+
colno: data.err.loc.column,
|
|
93
|
+
filename: data.err.loc.file,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
this.iframeClient.sendError(error);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
81
100
|
handleUnhandledrejection() {
|
|
82
101
|
window.addEventListener("unhandledrejection", (evt) => {
|
|
83
|
-
console.debug("handleUnhandledrejection", evt);
|
|
102
|
+
console.debug("[vite-shaper] handleUnhandledrejection", evt);
|
|
84
103
|
this.iframeClient.sendError({
|
|
85
104
|
errorType: "RUNTIME_ERROR",
|
|
86
105
|
timestamp: Date.now(),
|
|
@@ -92,7 +111,7 @@ class ErrorTracker {
|
|
|
92
111
|
|
|
93
112
|
handleError() {
|
|
94
113
|
window.addEventListener("error", (evt) => {
|
|
95
|
-
console.debug("handleError", evt);
|
|
114
|
+
console.debug("[vite-shaper] handleError", evt);
|
|
96
115
|
let message;
|
|
97
116
|
if (evt.error) {
|
|
98
117
|
message = evt.error.stack || evt.error.message;
|