fix(web): keep the stack when a view fails

Views caught their errors and showed only the message, so nothing said which
module or which line had failed — neither in the console, which never saw
the error, nor on the page.

The stack is now logged and offered on the page behind a disclosure, because
opening the developer console is not always an option on a self-hosted
panel.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
nocodeandClaude Opus 5 committed 2026-09-23 23:20:08 +02:00
1 parent 92c27aed9f
commit c031b4d9e2
2 files changed
+18 -3

No files matched your search

+2 -1
View File
@@ -310,8 +310,9 @@ async function renderView(host) {
const module = await import(route.module); const module = await import(route.module);
await module.render(host, { params: segments.slice(1), state }); await module.render(host, { params: segments.slice(1), state });
} catch (error) { } catch (error) {
console.error('[fws] échec de la vue', error);
const { errorBox } = await import('./core/ui.js'); const { errorBox } = await import('./core/ui.js');
mount(host, errorBox(error.message, { retry: () => renderView(host) })); mount(host, errorBox(error.message, { retry: () => renderView(host), error }));
} }
} }
+16 -2
View File
@@ -154,7 +154,12 @@ export const spinner = (label = 'Chargement…') =>
const looksLikeVersionMismatch = (message) => const looksLikeVersionMismatch = (message) =>
/Cannot read propert|undefined is not|is not a function|of undefined/i.test(String(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( h(
'div', 'div',
{ class: 'notice notice-error' }, { class: 'notice notice-error' },
@@ -167,6 +172,13 @@ export const errorBox = (message, { retry } = {}) =>
class: 'muted', 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.', 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' }), retry && button('Réessayer', retry, { tone: 'ghost' }),
); );
@@ -257,7 +269,9 @@ export async function renderAsync(host, load, build) {
const data = await load(); const data = await load();
mount(host, await build(data)); mount(host, await build(data));
} catch (error) { } 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; return host;
} }