« get me outta code hell

data: flash: improve missing-docoument-type reporting - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-04-03 16:35:07 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-04-03 16:35:07 -0300
commit822216b3df6525484df1b5ac436928023cc5789a (patch)
tree9c36cb347081ac932acd481916a9e5d597206aea /src/data
parent2d3a59502de2e6b7c19c3159be065f540b5cceeb (diff)
data: flash: improve missing-docoument-type reporting
Diffstat (limited to 'src/data')
-rw-r--r--src/data/things/flash.js20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/data/things/flash.js b/src/data/things/flash.js
index dc6a32df..d0aef04a 100644
--- a/src/data/things/flash.js
+++ b/src/data/things/flash.js
@@ -2,6 +2,7 @@ export const FLASH_DATA_FILE = 'flashes.yaml';
 
 import {input} from '#composite';
 import find from '#find';
+import {empty} from '#sugar';
 import {sortFlashesChronologically} from '#sort';
 import Thing from '#thing';
 import {anyOf, isColor, isContentString, isDirectory, isNumber, isString}
@@ -308,15 +309,22 @@ export class FlashSide extends Thing {
         : Flash),
 
     save(results) {
-      let thing;
-      for (let index = 0; thing = results[index]; index++) {
-        if (index === 0 && !(thing instanceof FlashSide)) {
-          throw new Error(`Expected a side at top of flash data file`);
-        }
+      // JavaScript likes you.
+
+      if (!empty(results) && !(results[0] instanceof FlashSide)) {
+        throw new Error(`Expected a side at top of flash data file`);
+      }
 
-        // JavaScript likes you.
+      let index = 0;
+      let thing;
+      for (; thing = results[index]; index++) {
         const flashSide = thing;
         const flashActRefs = [];
+
+        if (results[index + 1] instanceof Flash) {
+          throw new Error(`Expected an act to immediately follow a side`);
+        }
+
         for (
           index++;
           (thing = results[index]) && thing instanceof FlashAct;