Better error message if invalid theme

This commit is contained in:
Pieter Vander Vennet 2024-08-01 19:34:13 +02:00
parent 4fe2df61fe
commit 732189955b
3 changed files with 13 additions and 15 deletions

View file

@ -14,11 +14,7 @@ import licenses from "../assets/generated/license_info.json"
import TagRenderingConfig from "../Models/ThemeConfig/TagRenderingConfig" import TagRenderingConfig from "../Models/ThemeConfig/TagRenderingConfig"
import { FixImages } from "../Models/ThemeConfig/Conversion/FixImages" import { FixImages } from "../Models/ThemeConfig/Conversion/FixImages"
import questions from "../assets/generated/layers/questions.json" import questions from "../assets/generated/layers/questions.json"
import { import { DoesImageExist, PrevalidateTheme, ValidateThemeAndLayers } from "../Models/ThemeConfig/Conversion/Validation"
DoesImageExist,
PrevalidateTheme,
ValidateThemeAndLayers,
} from "../Models/ThemeConfig/Conversion/Validation"
import { DesugaringContext } from "../Models/ThemeConfig/Conversion/Conversion" import { DesugaringContext } from "../Models/ThemeConfig/Conversion/Conversion"
import { TagRenderingConfigJson } from "../Models/ThemeConfig/Json/TagRenderingConfigJson" import { TagRenderingConfigJson } from "../Models/ThemeConfig/Json/TagRenderingConfigJson"
import Hash from "./Web/Hash" import Hash from "./Web/Hash"
@ -109,11 +105,14 @@ export default class DetermineLayout {
layoutId, layoutId,
"The layout to load into MapComplete" "The layout to load into MapComplete"
).data ).data
const layout = AllKnownLayouts.allKnownLayouts.get(layoutId?.toLowerCase()) const id = layoutId?.toLowerCase()
if (layout === undefined) { const layouts = AllKnownLayouts.allKnownLayouts
throw "No builtin map theme with name " + layoutId + " exists" if (layouts.getConfig(id) === undefined) {
const alternatives = Utils.sortedByLevenshteinDistance(id, Array.from(layouts.keys()), i => i).slice(0, 3)
const msg = (`No builtin map theme with name ${layoutId} exists. Perhaps you meant one of ${alternatives.join(", ")}`)
throw msg
} }
return layout return layouts.get(id)
} }
public static async LoadLayoutFromHash( public static async LoadLayoutFromHash(
@ -162,6 +161,7 @@ export default class DetermineLayout {
return dict return dict
} }
private static getSharedTagRenderingOrder(): string[] { private static getSharedTagRenderingOrder(): string[] {
return questions.tagRenderings.map((tr) => tr.id) return questions.tagRenderings.map((tr) => tr.id)
} }
@ -200,11 +200,11 @@ export default class DetermineLayout {
id: json.id, id: json.id,
description: json.description, description: json.description,
descriptionTail: { descriptionTail: {
en: "<div class='alert'>Layer only mode.</div> The loaded custom theme actually isn't a custom theme, but only contains a layer.", en: "<div class='alert'>Layer only mode.</div> The loaded custom theme actually isn't a custom theme, but only contains a layer."
}, },
icon, icon,
title: json.name, title: json.name,
layers: [json], layers: [json]
} }
} }
@ -217,7 +217,7 @@ export default class DetermineLayout {
tagRenderings: DetermineLayout.getSharedTagRenderings(), tagRenderings: DetermineLayout.getSharedTagRenderings(),
tagRenderingOrder: DetermineLayout.getSharedTagRenderingOrder(), tagRenderingOrder: DetermineLayout.getSharedTagRenderingOrder(),
sharedLayers: knownLayersDict, sharedLayers: knownLayersDict,
publicLayers: new Set<string>(), publicLayers: new Set<string>()
} }
json = new FixLegacyTheme().convertStrict(json) json = new FixLegacyTheme().convertStrict(json)
const raw = json const raw = json
@ -241,7 +241,7 @@ export default class DetermineLayout {
} }
return new LayoutConfig(json, false, { return new LayoutConfig(json, false, {
definitionRaw: JSON.stringify(raw, null, " "), definitionRaw: JSON.stringify(raw, null, " "),
definedAtUrl: sourceUrl, definedAtUrl: sourceUrl
}) })
} }

View file

@ -1,5 +1,4 @@
import { QueryParameters } from "./Logic/Web/QueryParameters" import { QueryParameters } from "./Logic/Web/QueryParameters"
import SvelteUIElement from "./UI/Base/SvelteUIElement"
import AllThemesGui from "./UI/AllThemesGui.svelte" import AllThemesGui from "./UI/AllThemesGui.svelte"
const layout = QueryParameters.GetQueryParameter("layout", undefined).data ?? "" const layout = QueryParameters.GetQueryParameter("layout", undefined).data ?? ""

View file

@ -41,7 +41,6 @@ async function getAvailableLayers(): Promise<Set<string>> {
} }
async function main() { async function main() {
// @ts-ignore
try { try {
if (!webgl_support()) { if (!webgl_support()) {
throw "WebGL is not supported or not enabled. This is essential for MapComplete to function, please enable this." throw "WebGL is not supported or not enabled. This is essential for MapComplete to function, please enable this."