Skip to content

Commit 33f3bbf

Browse files
committed
improve error popup using sentry (local)
1 parent 435589f commit 33f3bbf

5 files changed

Lines changed: 168 additions & 5 deletions

File tree

‎package.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,15 @@
4444
"@codemirror/language": "^6.11.3",
4545
"@codemirror/state": "^6.5.2",
4646
"@codemirror/view": "^6.38.6",
47+
"@jridgewell/trace-mapping": "^0.3.31",
4748
"@melloware/coloris": "^0.25.0",
4849
"@nerimity/i18lite": "^1.2.0",
4950
"@nerimity/nevula": "^0.14.0",
5051
"@nerimity/solid-emoji-picker": "^0.4.9",
5152
"@nerimity/solid-i18lite": "^1.8.0",
5253
"@nerimity/solid-opus-media-recorder": "^1.0.1",
5354
"@nerimity/solid-turnstile": "^1.1.0",
55+
"@sentry/solid": "^10.32.1",
5456
"@solid-primitives/context": "^0.3.2",
5557
"@solid-primitives/keyed": "^1.5.2",
5658
"@solidjs/meta": "^0.29.4",

‎pnpm-lock.yaml‎

Lines changed: 77 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/common/color.ts‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ interface GradientData {
5959
}
6060

6161
export const parseGradient = (str: string): GradientData => {
62-
// Use optional chaining and provide a fallback string to prevent match error
6362
const match = str.match(/linear-gradient\((.*)\)/i)?.[1] ?? "";
6463

6564
if (!match) {
@@ -68,9 +67,8 @@ export const parseGradient = (str: string): GradientData => {
6867

6968
const parts = match.split(",").map((p) => p.trim());
7069

71-
// Check for angle safely
7270
let angle = 180;
73-
const firstPart = parts[0] ?? ""; // Fallback for empty array
71+
const firstPart = parts[0] ?? "";
7472

7573
if (firstPart.toLowerCase().includes("deg")) {
7674
const degMatch = firstPart.match(/^(\d+)deg$/i);
@@ -81,10 +79,8 @@ export const parseGradient = (str: string): GradientData => {
8179
}
8280

8381
const stops = parts.reduce((acc: ColorStop[], part) => {
84-
// Regex matches: #hex (group 1) and number (group 2)
8582
const stopMatch = part.match(/^(#[a-f0-9]{3,6})\s*(\d+)%$/i);
8683

87-
// Check if match exists and both capture groups are present
8884
if (stopMatch?.[1] && stopMatch?.[2]) {
8985
acc.push({
9086
color: stopMatch[1],

‎src/index.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import "./sentry";
12
import {
23
CustomPortalProvider,
34
toast,

‎src/sentry.tsx‎

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import * as Sentry from "@sentry/solid";
2+
3+
const showCrashPopup = (message: string) => {
4+
const existingDiv = document.getElementById("crash-reporter-popup");
5+
const div = existingDiv || document.createElement("div");
6+
div.id = "crash-reporter-popup";
7+
div.style.cssText = `
8+
position: fixed;
9+
top: 20px;
10+
left: 50%;
11+
transform: translateX(-50%);
12+
background: black;
13+
color: #fab1a0;
14+
padding: 20px;
15+
border-radius: 12px;
16+
z-index: 999999;
17+
box-shadow: 0 10px 30px rgba(0,0,0,0.5);
18+
max-width: 400px;
19+
width: 90%;
20+
border-left: 5px solid #ff7675;
21+
border: solid 1px rgba(255,255,255,0.4);
22+
`;
23+
24+
div.innerHTML = `
25+
<div style="font-weight: bold; font-size: 18px; margin-bottom: 10px; color: #ff7675;">
26+
⚠️ Nerimity Has Crashed
27+
</div>
28+
<div style="font-size: 14px; color: #dfe6e9; line-height: 1.4; margin-bottom: 20px; word-break: break-word;">
29+
${message}
30+
<div style="margin-top: 10px;opacity: 0.8">See the console for more details. <code style="color: #ff7675; font-size: 12px">(CTRL + SHIFT + I)</code></div>
31+
</div>
32+
<div style="display: flex; gap: 10px;">
33+
<button id="crash-reload" style="flex: 1; background: var(--alert-color); color: white; border: none; padding: 10px; border-radius: 6px; cursor: pointer; font-weight: bold;">
34+
Reload Page
35+
</button>
36+
<button id="crash-close" style="flex: 1; background: #1a1a1a; color: white; border: none; padding: 10px; border-radius: 6px; cursor: pointer;">
37+
Dismiss
38+
</button>
39+
</div>
40+
`;
41+
42+
if (!existingDiv) {
43+
document.body.appendChild(div);
44+
}
45+
document.getElementById("crash-reload")!.onclick = () => {
46+
window.location.reload();
47+
};
48+
49+
document.getElementById("crash-close")!.onclick = () => {
50+
div.remove();
51+
};
52+
};
53+
54+
Sentry.init({
55+
dsn: "http://0@0.ingest.sentry.io/0",
56+
async beforeSend(event) {
57+
const exception = event.exception?.values?.[0];
58+
const msg = exception?.value || "Unknown Error";
59+
const frame = exception?.stacktrace?.frames?.slice().reverse()[0];
60+
61+
if (frame) {
62+
try {
63+
const { TraceMap, originalPositionFor } = await import(
64+
"@jridgewell/trace-mapping"
65+
);
66+
const res = await fetch(`${frame.filename}.map`);
67+
const tracer = new TraceMap(await res.json());
68+
const orig = originalPositionFor(tracer, {
69+
line: frame.lineno!,
70+
column: frame.colno!,
71+
});
72+
73+
if (orig.source) {
74+
showCrashPopup(
75+
`${msg}<br/>${orig.source}:${orig.line}:${orig.column}`
76+
);
77+
return null;
78+
}
79+
} catch {
80+
//
81+
}
82+
}
83+
84+
showCrashPopup(`${msg}`);
85+
return null;
86+
},
87+
});

0 commit comments

Comments
 (0)