diff --git a/assets/themes/mapcomplete-changes/mapcomplete-changes.json b/assets/themes/mapcomplete-changes/mapcomplete-changes.json index 99de2cacb..fe87d0a9e 100644 --- a/assets/themes/mapcomplete-changes/mapcomplete-changes.json +++ b/assets/themes/mapcomplete-changes/mapcomplete-changes.json @@ -261,6 +261,10 @@ "if": "theme=ghostsigns", "then": "./assets/themes/advertising/wall_painting.svg" }, + { + "if": "theme=glutenfree", + "then": "./assets/themes/glutenfree/glutenfree.svg" + }, { "if": "theme=grb", "then": "./assets/themes/grb/logo.svg" diff --git a/scripts/Script.ts b/scripts/Script.ts index a12c551ed..c7e442fb3 100644 --- a/scripts/Script.ts +++ b/scripts/Script.ts @@ -22,7 +22,7 @@ export default abstract class Script { const green = (s) => "\x1b[92m" + s + "\x1b[0m" console.log(green("All done! (" + millisNeeded + " ms)")) }) - .catch((e) => console.log("ERROR:", e)) + .catch((e) => console.log("ERROR in script:", e)) } public printHelp() { diff --git a/src/Models/ThemeConfig/Conversion/Conversion.ts b/src/Models/ThemeConfig/Conversion/Conversion.ts index 357389523..b9799b442 100644 --- a/src/Models/ThemeConfig/Conversion/Conversion.ts +++ b/src/Models/ThemeConfig/Conversion/Conversion.ts @@ -35,7 +35,15 @@ export abstract class Conversion { public convertStrict(json: TIn, context?: ConversionContext): TOut { context ??= ConversionContext.construct([], []) context = context.inOperation(this.name) - const fixed = this.convert(json, context) + + let fixed: TOut + try { + fixed = this.convert(json, context) + } catch (e) { + console.error(e) + context.err("ERROR WHILE RUNNING STEP " + this.name+": "+e) + fixed = undefined + } for (const msg of context.messages) { if (msg.level === "debug") { continue @@ -46,11 +54,12 @@ export abstract class Conversion { throw new Error( [ "Detected one or more errors, stopping now:", - context.getAll("error").map((e) => e.context.path.join(".") + ": " + e.message), + context.getAll("error").map((e) => e.context.path.join(".") + ": " + e.message) ].join("\n\t") ) } return fixed + } public andThenF(f: (tout: TOut) => X): Conversion { @@ -60,7 +69,8 @@ export abstract class Conversion { public abstract convert(json: TIn, context: ConversionContext): TOut } -export abstract class DesugaringStep extends Conversion {} +export abstract class DesugaringStep extends Conversion { +} export class Pipe extends Conversion { private readonly _step0: Conversion @@ -247,7 +257,7 @@ export class Cached extends Conversion { const converted = this._step.convert(json, context) Object.defineProperty(json, this.key, { value: converted, - enumerable: false, + enumerable: false }) return converted } @@ -260,8 +270,8 @@ export class Fuse extends DesugaringStep { constructor(doc: string, ...steps: DesugaringStep[]) { super( (doc ?? "") + - "This fused pipeline of the following steps: " + - steps.map((s) => s.name).join(", "), + "This fused pipeline of the following steps: " + + steps.map((s) => s.name).join(", "), Utils.Dedup([].concat(...steps.map((step) => step.modifiedAttributes))), "Fuse(" + steps.map((s) => s.name).join(", ") + ")" ) diff --git a/src/Models/ThemeConfig/Conversion/ConversionContext.ts b/src/Models/ThemeConfig/Conversion/ConversionContext.ts index 302435985..ee38c8c62 100644 --- a/src/Models/ThemeConfig/Conversion/ConversionContext.ts +++ b/src/Models/ThemeConfig/Conversion/ConversionContext.ts @@ -124,9 +124,9 @@ export class ConversionContext { this.messages.push({ context: this, level: "warning", message }) } - err(message: string) { + err(...message: string[]) { this._hasErrors = true - this.messages.push({ context: this, level: "error", message }) + this.messages.push({ context: this, level: "error", message: message.join(" ") }) } info(message: string) { diff --git a/src/Models/ThemeConfig/Conversion/PrepareLayer.ts b/src/Models/ThemeConfig/Conversion/PrepareLayer.ts index 2199ff44b..9dd2a3f8f 100644 --- a/src/Models/ThemeConfig/Conversion/PrepareLayer.ts +++ b/src/Models/ThemeConfig/Conversion/PrepareLayer.ts @@ -83,7 +83,6 @@ class ExpandFilter extends DesugaringStep { context.err("Got undefined as filter expansion in "+tagRendering["id"]) continue } - console.log("Adding filter",filterName," due to", tagRendering["id"]) filters.push(filterName) } } diff --git a/src/Models/ThemeConfig/Conversion/PrepareTheme.ts b/src/Models/ThemeConfig/Conversion/PrepareTheme.ts index a634944c3..dca64f6b9 100644 --- a/src/Models/ThemeConfig/Conversion/PrepareTheme.ts +++ b/src/Models/ThemeConfig/Conversion/PrepareTheme.ts @@ -71,6 +71,10 @@ class SubstituteLayer extends Conversion { private static CalculateDependencies( alreadyLoaded: LayerConfigJson[], allKnownLayers: Map, - themeId: string + themeId: string, + context: ConversionContext ): { config: LayerConfigJson; reason: string }[] { const dependenciesToAdd: { config: LayerConfigJson; reason: string }[] = [] const loadedLayerIds: Set = new Set(alreadyLoaded.map((l) => l?.id)) @@ -388,6 +393,7 @@ class AddDependencyLayersToTheme extends DesugaringStep { }[] = [] for (const layerConfig of alreadyLoaded) { + try { const layerDeps = DependencyCalculator.getLayerDependencies( new LayerConfig(layerConfig, themeId + "(dependencies)") @@ -396,7 +402,7 @@ class AddDependencyLayersToTheme extends DesugaringStep { } catch (e) { console.error(e) throw ( - "Detecting layer dependencies for " + layerConfig.id + " failed due to " + e + "Detecting layer dependencies for " + layerConfig?.id + " failed due to " + e ) } } @@ -467,7 +473,8 @@ class AddDependencyLayersToTheme extends DesugaringStep { const dependencies = AddDependencyLayersToTheme.CalculateDependencies( layers, allKnownLayers, - theme.id + theme.id, + context ) if (dependencies.length > 0) { for (const dependency of dependencies) { diff --git a/src/Models/ThemeConfig/FilterConfig.ts b/src/Models/ThemeConfig/FilterConfig.ts index c09c2d9d3..ea5eef310 100644 --- a/src/Models/ThemeConfig/FilterConfig.ts +++ b/src/Models/ThemeConfig/FilterConfig.ts @@ -25,8 +25,11 @@ export default class FilterConfig { public readonly defaultSelection?: number constructor(json: FilterConfigJson, context: string) { + if(typeof json === "string"){ + throw "Got a non-expanded filter, just a string: "+json + } if (json.options === undefined) { - throw `A filter without options was given at ${context}` + throw `A filter without options was given at ${context}. The ID is ${JSON.stringify(json)}` } if (json.id === undefined) { throw `A filter without id was found at ${context}` diff --git a/src/Models/ThemeConfig/LayerConfig.ts b/src/Models/ThemeConfig/LayerConfig.ts index 262dd52fc..d2cd38ef3 100644 --- a/src/Models/ThemeConfig/LayerConfig.ts +++ b/src/Models/ThemeConfig/LayerConfig.ts @@ -72,7 +72,7 @@ export default class LayerConfig extends WithContextLoader { private readonly _basedOn: string | undefined constructor(json: LayerConfigJson, context?: string, official: boolean = true) { - context = context + "." + json.id + context = context + "." + json?.id const translationContext = "layers:" + json.id super(json, context) this.id = json.id @@ -292,7 +292,9 @@ export default class LayerConfig extends WithContextLoader { this.filterIsSameAs = json.filter["sameAs"] this.filters = [] } else { - this.filters = (json.filter ?? []).map((option, i) => { + this.filters = (json.filter ?? []) + .filter(f => typeof f !== "string") + .map((option, i) => { return new FilterConfig(option, `layers:${this.id}.filter.${i}`) }) }