forked from MapComplete/MapComplete
		
	Better error handling
This commit is contained in:
		
							parent
							
								
									700cad1000
								
							
						
					
					
						commit
						979041dacb
					
				
					 6 changed files with 44 additions and 21 deletions
				
			
		|  | @ -216,13 +216,18 @@ export class Fuse<T> extends DesugaringStep<T> { | |||
|         const information = [] | ||||
|         for (let i = 0; i < this.steps.length; i++) { | ||||
|             const step = this.steps[i]; | ||||
|             let r = step.convert(json, "While running step " + step.name + ": " + context) | ||||
|             errors.push(...r.errors ?? []) | ||||
|             warnings.push(...r.warnings ?? []) | ||||
|             information.push(...r.information ?? []) | ||||
|             json = r.result | ||||
|             if (errors.length > 0) { | ||||
|                 break; | ||||
|             try{ | ||||
|                 let r = step.convert(json, "While running step " + step.name + ": " + context) | ||||
|                 errors.push(...r.errors ?? []) | ||||
|                 warnings.push(...r.warnings ?? []) | ||||
|                 information.push(...r.information ?? []) | ||||
|                 json = r.result | ||||
|                 if (errors.length > 0) { | ||||
|                     break; | ||||
|                 } | ||||
|             }catch(e){ | ||||
|                 console.error("Step "+step.name+" failed due to "+e); | ||||
|                 throw e | ||||
|             } | ||||
|         } | ||||
|         return { | ||||
|  |  | |||
|  | @ -479,6 +479,7 @@ export class PrepareTheme extends Fuse<LayoutConfigJson> { | |||
|     }) { | ||||
|         super( | ||||
|             "Fully prepares and expands a theme", | ||||
| 
 | ||||
|             new AddContextToTransltionsInLayout(), | ||||
|             new PreparePersonalTheme(state), | ||||
|             new WarnForUnsubstitutedLayersInTheme(), | ||||
|  |  | |||
|  | @ -217,12 +217,17 @@ class MiscThemeChecks extends DesugaringStep<LayoutConfigJson>{ | |||
|      | ||||
|     convert(json: LayoutConfigJson, context: string): { result: LayoutConfigJson; errors?: string[]; warnings?: string[]; information?: string[] } { | ||||
|         const warnings = [] | ||||
|         const errors = [] | ||||
|         if(json.id !== "personal" && (json.layers === undefined || json.layers.length === 0)){ | ||||
|             errors.push("The theme "+json.id+" has no 'layers' defined ("+context+")") | ||||
|         } | ||||
|         if(json.socialImage === ""){ | ||||
|             warnings.push("Social image for theme "+json.id+" is the emtpy string") | ||||
|         } | ||||
|         return { | ||||
|             result :json, | ||||
|             warnings | ||||
|             warnings, | ||||
|             errors | ||||
|         }; | ||||
|     } | ||||
| } | ||||
|  | @ -231,8 +236,8 @@ export class PrevalidateTheme extends Fuse<LayoutConfigJson> { | |||
| 
 | ||||
|     constructor() { | ||||
|         super("Various consistency checks on the raw JSON", | ||||
|             new OverrideShadowingCheck(), | ||||
|             new MiscThemeChecks() | ||||
|             new MiscThemeChecks(), | ||||
|             new OverrideShadowingCheck() | ||||
|         ); | ||||
| 
 | ||||
|     } | ||||
|  |  | |||
|  | @ -18,9 +18,12 @@ export default interface UnitConfigJson { | |||
| 
 | ||||
| export interface ApplicableUnitJson { | ||||
|     /** | ||||
|      * The canonical value which will be added to the text. | ||||
|      * The canonical value which will be added to the value in OSM. | ||||
|      * e.g. "m" for meters | ||||
|      * If the user inputs '42', the canonical value will be added and it'll become '42m' | ||||
|      * If the user inputs '42', the canonical value will be added and it'll become '42m'. | ||||
|      *  | ||||
|      * Important: often, _no_ canonical values are expected, e.g. in the case of 'maxspeed' where 'km/h' is the default. | ||||
|      * In this case, an empty string should be used | ||||
|      */ | ||||
|     canonicalDenomination: string, | ||||
|     /** | ||||
|  |  | |||
|  | @ -134,6 +134,9 @@ export default class LayerConfig extends WithContextLoader { | |||
| 
 | ||||
|         this.allowSplit = json.allowSplit ?? false; | ||||
|         this.name = Translations.T(json.name, translationContext + ".name"); | ||||
|         if(json.units!==undefined && !Array.isArray(json.units)){ | ||||
|             throw "At "+context+".units: the 'units'-section should be a list; you probably have an object there" | ||||
|         } | ||||
|         this.units = (json.units ?? []).map(((unitJson, i) => Unit.fromJson(unitJson, `${context}.unit[${i}]`))) | ||||
| 
 | ||||
|         if (json.description !== undefined) { | ||||
|  |  | |||
|  | @ -203,16 +203,22 @@ class LayerOverviewUtils { | |||
|             const themePath = themeInfo.path | ||||
| 
 | ||||
|             new PrevalidateTheme().convertStrict(themeFile, themePath) | ||||
|             themeFile = new PrepareTheme(convertState).convertStrict(themeFile, themePath) | ||||
| 
 | ||||
|             if(knownImagePaths === undefined){ | ||||
|                 throw "Could not load known images/licenses" | ||||
|             try{ | ||||
|                  | ||||
|                 themeFile = new PrepareTheme(convertState).convertStrict(themeFile, themePath) | ||||
|      | ||||
|                 if(knownImagePaths === undefined){ | ||||
|                     throw "Could not load known images/licenses" | ||||
|                 } | ||||
|                 new ValidateThemeAndLayers(knownImagePaths, themePath, true, convertState.tagRenderings) | ||||
|                     .convertStrict(themeFile, themePath) | ||||
|      | ||||
|                 this.writeTheme(themeFile) | ||||
|                 fixed.set(themeFile.id, themeFile) | ||||
|             }catch(e){ | ||||
|                 console.error("ERROR: could not prepare theme "+themePath+" due to "+e) | ||||
|                 throw e; | ||||
|             } | ||||
|             new ValidateThemeAndLayers(knownImagePaths, themePath, true, convertState.tagRenderings) | ||||
|                 .convertStrict(themeFile, themePath) | ||||
| 
 | ||||
|             this.writeTheme(themeFile) | ||||
|             fixed.set(themeFile.id, themeFile) | ||||
|         } | ||||
| 
 | ||||
|         this.writeSmallOverview(themeFiles.map(tf => { | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue