From 822216b3df6525484df1b5ac436928023cc5789a Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Wed, 3 Apr 2024 16:35:07 -0300 Subject: data: flash: improve missing-docoument-type reporting --- src/data/things/flash.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src/data') 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; -- cgit 1.3.0-6-gf8a5