From 599b39370bb41505afe5761aea6859d1c7339c9e Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Thu, 8 Sep 2022 05:00:55 +0000 Subject: [PATCH] catch bad NAT command implementations at runtime --- .../nat-archive-tool/src/nat/ArchiveController.kiss | 10 ++++++++-- projects/nat-archive-tool/src/nat/Lib.kiss | 11 +++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/projects/nat-archive-tool/src/nat/ArchiveController.kiss b/projects/nat-archive-tool/src/nat/ArchiveController.kiss index 864175a2..e3073bf7 100644 --- a/projects/nat-archive-tool/src/nat/ArchiveController.kiss +++ b/projects/nat-archive-tool/src/nat/ArchiveController.kiss @@ -142,8 +142,14 @@ [] &mut lastCollector (lambda [] - (set lastChangeSet (the ChangeSet (Reflect.callMethod null command.handler collectedArgs))) - (when lastChangeSet (ui.handleChanges archive lastChangeSet)))] + (let [result (Reflect.callMethod null command.handler collectedArgs)] + (assert !(Prelude.isNull result) "Command implementation forgot to return a ChangeSet") + (set lastChangeSet (the ChangeSet result)) + + (when lastChangeSet + (doFor e lastChangeSet + (assert (and e (isEntry e)) "Lib function forgot to return the Entry that was modified")) + (ui.handleChanges archive lastChangeSet))))] // To facilitate asynchronous arg input via UI, we need to construct an insanely complicated nested callback to give the UI (doFor arg (reverse command.args) (set lastCollector (_composeArgCollector collectedArgs arg stream lastCollector))) diff --git a/projects/nat-archive-tool/src/nat/Lib.kiss b/projects/nat-archive-tool/src/nat/Lib.kiss index 6a892b97..c74ee73b 100644 --- a/projects/nat-archive-tool/src/nat/Lib.kiss +++ b/projects/nat-archive-tool/src/nat/Lib.kiss @@ -136,9 +136,16 @@ (if (hasComponent e Connections) (withWritableComponents archive e [conn Connections] (doFor e2 entriesToConnect (dictSet conn e2.id 1))) - (addComponent archive e Connections (for e2 entriesToConnect =>e2.id 1)))) + (addComponent archive e Connections (for e2 entriesToConnect =>e2.id 1))) + ) (function removeConnections [:nat.Archive archive :nat.Entry e :Array entriesToRemove] (when (hasComponent e Connections) (withWritableComponents archive e [conn Connections] - (doFor e2 entriesToRemove (conn.remove e2.id))))) + (doFor e2 entriesToRemove (conn.remove e2.id)))) + e) + +(function isEntry [o] + (let [fields (Reflect.fields o)] + (and (= fields.length 3) + (apply and (for f ["id" "components" "files"] (contains fields f)))))) \ No newline at end of file