From ca36bf1b646c893557b6188849d416528a5308e6 Mon Sep 17 00:00:00 2001 From: Zaid Abdulla Date: Mon, 25 Jan 2021 16:30:47 -0800 Subject: [PATCH] Handle UI component errors gracefully --- ui/components.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ui/components.ts b/ui/components.ts index 20ea419..bf783e9 100644 --- a/ui/components.ts +++ b/ui/components.ts @@ -137,9 +137,13 @@ export function contextifyComponent(component: ComponentTypes): ComponentTypes { const view = state.view; state.view = function (vnode) { const context = vnodeContext.get(vnode) || {}; - const res = Reflect.apply(view, this, [vnode]); - applyContext(res, context); - return res; + try { + const res = Reflect.apply(view, this, [vnode]); + applyContext(res, context); + return res; + } catch (err) { + return m("p.error", { title: err.message }, "Error!"); + } }; return state; };