diff --git a/src/ui/web/general/SwitchView.js b/src/ui/web/general/SwitchView.js index 80ee7198..66950052 100644 --- a/src/ui/web/general/SwitchView.js +++ b/src/ui/web/general/SwitchView.js @@ -1,3 +1,5 @@ +import {errorToDOM} from "./error.js"; + export class SwitchView { constructor(defaultView) { this._childView = defaultView; @@ -23,7 +25,12 @@ export class SwitchView { const oldRoot = this.root(); this._childView.unmount(); this._childView = newView; - const newRoot = this._childView.mount(); + let newRoot; + try { + newRoot = this._childView.mount(); + } catch (err) { + newRoot = errorToDOM(err); + } const parent = oldRoot.parentElement; if (parent) { parent.replaceChild(newRoot, oldRoot); diff --git a/src/ui/web/general/error.js b/src/ui/web/general/error.js new file mode 100644 index 00000000..c218504e --- /dev/null +++ b/src/ui/web/general/error.js @@ -0,0 +1,12 @@ +import {tag} from "./html.js"; + +export function errorToDOM(error) { + const stack = new Error().stack; + const callee = stack.split("\n")[1]; + return tag.div([ + tag.h2("Something went wrong…"), + tag.h3(error.message), + tag.p(`This occurred while running ${callee}.`), + tag.pre(error.stack), + ]); +}