From c81a3c95090ddabfbb77eeaefa96e7c9339e6824 Mon Sep 17 00:00:00 2001
From: David Sehnal <david.sehnal@gmail.com>
Date: Wed, 21 Nov 2018 11:34:00 +0100
Subject: [PATCH] mol-state: set error state to descendants of Null state
 object

---
 src/mol-state/state.ts | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/src/mol-state/state.ts b/src/mol-state/state.ts
index 53a758b1c..a02c30281 100644
--- a/src/mol-state/state.ts
+++ b/src/mol-state/state.ts
@@ -406,9 +406,11 @@ function _findNewCurrent(tree: StateTree, ref: Ref, deletes: Set<Ref>): Ref {
 }
 
 /** Set status and error text of the cell. Remove all existing objects in the subtree. */
-function doError(ctx: UpdateContext, ref: Ref, errorText: string | undefined) {
-    ctx.hadError = true;
-    (ctx.parent as any as { errorFree: boolean }).errorFree = false;
+function doError(ctx: UpdateContext, ref: Ref, errorText: string | undefined, silent: boolean) {
+    if (!silent) {
+        ctx.hadError = true;
+        (ctx.parent as any as { errorFree: boolean }).errorFree = false;
+    }
 
     if (errorText) {
         setCellStatus(ctx, ref, 'error', errorText);
@@ -428,7 +430,7 @@ function doError(ctx: UpdateContext, ref: Ref, errorText: string | undefined) {
     while (true) {
         const next = children.next();
         if (next.done) return;
-        doError(ctx, next.value, void 0);
+        doError(ctx, next.value, void 0, silent);
     }
 }
 
@@ -464,19 +466,16 @@ async function updateSubtree(ctx: UpdateContext, root: Ref) {
     } catch (e) {
         ctx.changed = true;
         if (!ctx.hadError) ctx.newCurrent = root;
-        doError(ctx, root, '' + e);
+        doError(ctx, root, '' + e, false);
         return;
     }
 
-    // Do not continue the updates if the object is null
-    // TODO: set the states to something "nicer"?
-    if (isNull) return;
-
     const children = ctx.tree.children.get(root).values();
     while (true) {
         const next = children.next();
         if (next.done) return;
-        await updateSubtree(ctx, next.value);
+        if (isNull) doError(ctx, next.value, 'Parent is null', true);
+        else await updateSubtree(ctx, next.value);
     }
 }
 
-- 
GitLab