forked from MapComplete/MapComplete
		
	Scripts: add error message in case of incorrect ID
This commit is contained in:
		
							parent
							
								
									29db2664c3
								
							
						
					
					
						commit
						55cc06db1a
					
				
					 1 changed files with 8 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -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
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue