From c19febadc2e06685effaaea5c292e65fffc43811 Mon Sep 17 00:00:00 2001 From: Tom Date: Thu, 21 Jan 2021 17:25:35 +0000 Subject: [PATCH] Better error handlin Added error handling of .value() after multiple .get() chained on non-existant values. Credit to @LucAngevare for his contributions. --- src/stormdb.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/stormdb.js b/src/stormdb.js index b832975..f093a7f 100644 --- a/src/stormdb.js +++ b/src/stormdb.js @@ -119,6 +119,9 @@ class StormDB { value() { let data = this.state; for (let i = 0; i < this.pointers.length; i++) { + if (i < this.pointers.length - 1 && !data[this.pointers[i]]) { + throw new Error("Can't run .value() on non-existant data."); + } data = data[this.pointers[i]]; }