diff --git a/src/web/public/app.js b/src/web/public/app.js index 38d9b14..9d27d27 100644 --- a/src/web/public/app.js +++ b/src/web/public/app.js @@ -310,8 +310,9 @@ async function renderView(host) { const module = await import(route.module); await module.render(host, { params: segments.slice(1), state }); } catch (error) { + console.error('[fws] échec de la vue', error); const { errorBox } = await import('./core/ui.js'); - mount(host, errorBox(error.message, { retry: () => renderView(host) })); + mount(host, errorBox(error.message, { retry: () => renderView(host), error })); } } diff --git a/src/web/public/core/ui.js b/src/web/public/core/ui.js index 8f25c26..0506aaa 100644 --- a/src/web/public/core/ui.js +++ b/src/web/public/core/ui.js @@ -154,7 +154,12 @@ export const spinner = (label = 'Chargement…') => const looksLikeVersionMismatch = (message) => /Cannot read propert|undefined is not|is not a function|of undefined/i.test(String(message)); -export const errorBox = (message, { retry } = {}) => +/** + * `error` carries the stack; `message` alone leaves nobody able to say where it + * came from. Showing it on the page matters for a self-hosted panel, where + * opening the developer console is not always an option. + */ +export const errorBox = (message, { retry, error = null } = {}) => h( 'div', { class: 'notice notice-error' }, @@ -167,6 +172,13 @@ export const errorBox = (message, { retry } = {}) => class: 'muted', text: 'Cette erreur vient en général d’une interface plus ancienne que l’API : recharge avec Ctrl+Shift+R, et si elle persiste, re-téléverse le dossier src/web/public.', }), + error?.stack && + h( + 'details', + {}, + h('summary', { text: 'Détails techniques' }), + h('pre', {}, h('code', { text: error.stack })), + ), ), retry && button('Réessayer', retry, { tone: 'ghost' }), ); @@ -257,7 +269,9 @@ export async function renderAsync(host, load, build) { const data = await load(); mount(host, await build(data)); } catch (error) { - mount(host, errorBox(error.message, { retry: () => renderAsync(host, load, build) })); + // Swallowing the stack leaves a failure impossible to place. + console.error('[fws] échec du rendu', error); + mount(host, errorBox(error.message, { retry: () => renderAsync(host, load, build), error })); } return host; }