commit b7c06419ad03e1284e97c08509d691874c7673e2
parent 9349cd6b0a3c900c82d981a2dfe5ef231ebef225
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date: Sun, 25 Aug 2024 14:03:18 -0700
Add more checks and more information to errors
Diffstat:
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/files/floorplans/floorplan/backend.js b/files/floorplans/floorplan/backend.js
@@ -404,6 +404,11 @@ export class FloorplanBackend {
*/
key = uniqueKey(this.cache[type])
}
+ let inputKey = key
+ key = Number(key)
+ if (isNaN(key)) {
+ throw new Error(`${inputKey}: Invalid key, only numeric keys are accepted`)
+ }
if (type === "pointmaps") {
this.updateMappedPoints(value.a, value.b, key)
@@ -475,7 +480,7 @@ export class FloorplanBackend {
throw new Error("Only walls and doors allowed in pointmap so far")
}
if (!this.cache.points[a] || !this.cache.points[b]) {
- throw new Error("Pointmap must reference existing points")
+ throw new Error(`${a}, ${b}: Pointmap must reference existing points`)
}
a = Number(a)
@@ -775,11 +780,11 @@ export function parsePath(path) {
if (a.length != 3) {
throw new Error("Invalid path")
}
- return newRef(a[1], a[2])
+ return newRef(a[1], Number(a[2]))
}
export function newRef(type, id) {
- return { type: type, id: id }
+ return { type: String(type), id: Number(id) }
}
function uniqueKey(obj) {