Scripts: add error message in case of incorrect ID

This commit is contained in:
Pieter Vander Vennet 2025-05-23 18:03:07 +02:00
parent 0e91656dd6
commit 567f77fb2b

View file

@ -203,6 +203,9 @@ class LayerBuilder extends Conversion<object, Map<string, LayerConfigJson>> {
context = context.inOperation("building Layer " + id).enters("layer", id)
const config = this._layerConfigJsons.get(id)
if (config.id !== id) {
context.err("Invalid ID: expected", id, "but got", id)
}
const prepped = this.prepareLayer.convert(config, context)
this._loadedIds.add(id)
this._desugaringState.sharedLayers.set(id, prepped)
@ -760,11 +763,15 @@ class LayerOverviewUtils extends Script {
ScriptUtils.erasableLog(
`Parsing layerConfig ${i + 1}/${allPaths.length}: ${path} `
)
const expectedId = path.match(/.*\/([a-z_0-9]+).json/)[1]
try {
const data = JSON.parse(readFileSync(path, "utf8"))
results.push(data)
if (data.id !== expectedId) {
throw "Wrong ID or location for file " + path + "; expected " + expectedId + " but got " + data.id
}
} catch (e) {
throw "Could not parse layer file " + path
throw "Could not parse layer file " + path + " due to " + e
}
}