{"record":{"id":"4929ef6b4d05673e","repo":"koala73/worldmonitor","slug":"unknown-mission-preset-presetid","errorCode":null,"errorMessage":"Unknown mission preset: ${presetId}","messagePattern":"Unknown mission preset: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/services/mission-presets.ts","lineNumber":449,"sourceCode":"  }\n}\n\nexport function dismissMissionPresetPrompt(): void {\n  try {\n    localStorage.setItem(MISSION_PRESET_DISMISSED_KEY, '1');\n  } catch {\n    // Ignore storage failures.\n  }\n}\n\nexport function applyMissionPresetToState(\n  presetId: MissionPresetId,\n  currentPanelSettings: Record<string, PanelConfig>,\n  defaultLayers: MapLayers = DEFAULT_MAP_LAYERS,\n  variant: string = SITE_VARIANT,\n): AppliedMissionPreset {\n  const preset = getMissionPreset(presetId);\n  if (!preset) throw new Error(`Unknown mission preset: ${presetId}`);\n  if (!isMissionPresetAvailableForVariant(preset, variant)) {\n    throw new Error(`Mission preset ${presetId} is not available on this variant`);\n  }\n\n  const variantPanels = getVariantDefaultPanels(variant);\n  const variantPanelSet = new Set(variantPanels);\n  const matchingPresetPanels = preset.panels.filter((key) => key !== 'map' && variantPanelSet.has(key));\n  const useVariantDefaultPanels = matchingPresetPanels.length < MIN_PRESET_PANEL_MATCHES;\n  const selectedPanels = useVariantDefaultPanels\n    ? withMapPanel(variantPanels)\n    : preset.panels.filter((key) => key === 'map' || variantPanelSet.has(key));\n  const selectedPanelSet = new Set(selectedPanels);\n  const nextPanelSettings: Record<string, PanelConfig> = {};\n  const allKeys = new Set([\n    ...Object.keys(DEFAULT_PANELS),\n    ...Object.keys(ALL_PANELS),\n    ...Object.keys(currentPanelSettings),\n    ...selectedPanels,","sourceCodeStart":431,"sourceCodeEnd":467,"githubUrl":"https://github.com/koala73/worldmonitor/blob/9361220cc013571781071f0206e4d80fd14b2f7f/src/services/mission-presets.ts#L431-L467","documentation":"applyMissionPresetToState resolves the requested preset id through getMissionPreset(); the lookup returns undefined for any id that is not one of the bundled presets, and the function throws 'Unknown mission preset: <id>'. It is a fail-fast validation of the presetId argument before any panel/map state is computed.","triggerScenarios":"Calling applyMissionPresetToState (or applyMissionPreset) with an id that is not in the preset registry: a typo, a preset removed/renamed in a newer version, a custom string cast to MissionPresetId, or an id read from stale localStorage/URL state that no longer exists.","commonSituations":"Passing a human label ('Crisis Watch') instead of the preset id; upgrading the app where stored mission preset ids changed; WebMCP agents guessing preset ids; URL-synced state carrying a deleted preset id.","solutions":["Use an id from the exported preset list (e.g. via getMissionPresetIds()/the registry) rather than a hand-written string.","Validate the id with getMissionPreset(presetId) before applying and fall back to the default preset when it returns undefined.","Migrate stale stored ids: sanitize loadStoredMissionPreset()/URL state against the current registry and clear unknown values.","For agents, enumerate available presets via the WebMCP picker instead of guessing ids."],"exampleFix":"// before\napplyMissionPreset('crisis watch' as MissionPresetId);\n// after\nconst id = 'crisis-watch';\nif (!getMissionPreset(id)) {\n  console.warn(`Preset ${id} not found, using default`);\n}\napplyMissionPreset(getMissionPreset(id) ? id : DEFAULT_MISSION_PRESET_ID);","handlingStrategy":"validation","validationCode":"import { getMissionPreset } from '../services/mission-presets';\nif (!getMissionPreset(presetId)) {\n  presetId = DEFAULT_MISSION_PRESET_ID;\n}\n","typeGuard":"function isKnownPreset(id: string): id is MissionPresetId {\n  return getMissionPreset(id as MissionPresetId) != null;\n}\n","tryCatchPattern":"try {\n  applyMissionPreset(presetId);\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Unknown mission preset')) {\n    applyMissionPreset(DEFAULT_MISSION_PRESET_ID);\n  } else throw e;\n}\n","preventionTips":["Always source preset ids from the exported preset registry, never hand-typed strings","Sanitize ids loaded from localStorage or URL state against the current registry at boot","Enumerate available presets for agents via the WebMCP picker API","Add a migration/cleanup step when renaming or removing presets"],"tags":["validation","invalid-argument","mission-presets","configuration"],"backgroundTag":"invalid-enum-value","analyzedSha":"9361220cc013571781071f0206e4d80fd14b2f7f","analyzedAt":"2026-09-01T10:32:37.851Z","contentChangedAt":"2026-09-01T10:32:37.851Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}