49 lines
1.7 KiB
JavaScript
49 lines
1.7 KiB
JavaScript
import App from './App.svelte'
|
|
|
|
// ===== Global frontend error diagnostics =====
|
|
// These catch runtime errors that would otherwise cause a silent blank window.
|
|
|
|
window.addEventListener('error', (event) => {
|
|
const msg = event.error ? String(event.error) : event.message
|
|
const stack = event.error && event.error.stack ? event.error.stack : ''
|
|
console.error('[Frontend Error]', msg, stack)
|
|
try {
|
|
if (window['go'] && window['go']['main'] && window['go']['main']['App'] && typeof window['go']['main']['App']['FrontendLog'] === 'function') {
|
|
window['go']['main']['App']['FrontendLog']('error', msg, stack)
|
|
}
|
|
} catch (e) {
|
|
// Backend not ready — ignore
|
|
}
|
|
})
|
|
|
|
window.addEventListener('unhandledrejection', (event) => {
|
|
const reason = event.reason
|
|
const msg = reason instanceof Error ? String(reason) : JSON.stringify(reason)
|
|
const stack = reason instanceof Error && reason.stack ? reason.stack : ''
|
|
console.error('[Unhandled Promise Rejection]', msg, stack)
|
|
try {
|
|
if (window['go'] && window['go']['main'] && window['go']['main']['App'] && typeof window['go']['main']['App']['FrontendLog'] === 'function') {
|
|
window['go']['main']['App']['FrontendLog']('error', 'Unhandled rejection: ' + msg, stack)
|
|
}
|
|
} catch (e) {
|
|
// Backend not ready — ignore
|
|
}
|
|
})
|
|
|
|
// Mount App with error fallback
|
|
try {
|
|
new App({
|
|
target: document.getElementById('app')
|
|
})
|
|
} catch (e) {
|
|
console.error('[Fatal] App mount failed:', e)
|
|
const el = document.getElementById('app')
|
|
if (el) {
|
|
el.innerHTML = '<div style="padding:24px;color:#ff6b6b;font-family:monospace;white-space:pre-wrap">'
|
|
+ '<h2>Frontend Runtime Error</h2>'
|
|
+ '<p>' + String(e) + '</p>'
|
|
+ (e.stack ? '<pre>' + e.stack + '</pre>' : '')
|
|
+ '</div>'
|
|
}
|
|
}
|