Better error handling

This commit is contained in:
pietervdvn 2022-04-22 03:17:40 +02:00
parent 700cad1000
commit 979041dacb
6 changed files with 44 additions and 21 deletions

View file

@ -216,13 +216,18 @@ export class Fuse<T> extends DesugaringStep<T> {
const information = [] const information = []
for (let i = 0; i < this.steps.length; i++) { for (let i = 0; i < this.steps.length; i++) {
const step = this.steps[i]; const step = this.steps[i];
let r = step.convert(json, "While running step " + step.name + ": " + context) try{
errors.push(...r.errors ?? []) let r = step.convert(json, "While running step " + step.name + ": " + context)
warnings.push(...r.warnings ?? []) errors.push(...r.errors ?? [])
information.push(...r.information ?? []) warnings.push(...r.warnings ?? [])
json = r.result information.push(...r.information ?? [])
if (errors.length > 0) { json = r.result
break; if (errors.length > 0) {
break;
}
}catch(e){
console.error("Step "+step.name+" failed due to "+e);
throw e
} }
} }
return { return {

View file

@ -479,6 +479,7 @@ export class PrepareTheme extends Fuse<LayoutConfigJson> {
}) { }) {
super( super(
"Fully prepares and expands a theme", "Fully prepares and expands a theme",
new AddContextToTransltionsInLayout(), new AddContextToTransltionsInLayout(),
new PreparePersonalTheme(state), new PreparePersonalTheme(state),
new WarnForUnsubstitutedLayersInTheme(), new WarnForUnsubstitutedLayersInTheme(),

View file

@ -217,12 +217,17 @@ class MiscThemeChecks extends DesugaringStep<LayoutConfigJson>{
convert(json: LayoutConfigJson, context: string): { result: LayoutConfigJson; errors?: string[]; warnings?: string[]; information?: string[] } { convert(json: LayoutConfigJson, context: string): { result: LayoutConfigJson; errors?: string[]; warnings?: string[]; information?: string[] } {
const warnings = [] 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 === ""){ if(json.socialImage === ""){
warnings.push("Social image for theme "+json.id+" is the emtpy string") warnings.push("Social image for theme "+json.id+" is the emtpy string")
} }
return { return {
result :json, result :json,
warnings warnings,
errors
}; };
} }
} }
@ -231,8 +236,8 @@ export class PrevalidateTheme extends Fuse<LayoutConfigJson> {
constructor() { constructor() {
super("Various consistency checks on the raw JSON", super("Various consistency checks on the raw JSON",
new OverrideShadowingCheck(), new MiscThemeChecks(),
new MiscThemeChecks() new OverrideShadowingCheck()
); );
} }

View file

@ -18,9 +18,12 @@ export default interface UnitConfigJson {
export interface ApplicableUnitJson { 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 * 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, canonicalDenomination: string,
/** /**

View file

@ -134,6 +134,9 @@ export default class LayerConfig extends WithContextLoader {
this.allowSplit = json.allowSplit ?? false; this.allowSplit = json.allowSplit ?? false;
this.name = Translations.T(json.name, translationContext + ".name"); 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}]`))) this.units = (json.units ?? []).map(((unitJson, i) => Unit.fromJson(unitJson, `${context}.unit[${i}]`)))
if (json.description !== undefined) { if (json.description !== undefined) {

View file

@ -203,16 +203,22 @@ class LayerOverviewUtils {
const themePath = themeInfo.path const themePath = themeInfo.path
new PrevalidateTheme().convertStrict(themeFile, themePath) new PrevalidateTheme().convertStrict(themeFile, themePath)
themeFile = new PrepareTheme(convertState).convertStrict(themeFile, themePath) try{
if(knownImagePaths === undefined){ themeFile = new PrepareTheme(convertState).convertStrict(themeFile, themePath)
throw "Could not load known images/licenses"
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 => { this.writeSmallOverview(themeFiles.map(tf => {