{"record":{"id":"1f59c94338f08024","repo":"withastro/astro","slug":"incorrect-value-for-key","errorCode":null,"errorMessage":"Incorrect value for ${key}","messagePattern":"Incorrect value for (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"packages/astro/src/preferences/index.ts","lineNumber":78,"sourceCode":"\nexport function isValidKey(key: string): key is PreferenceKey {\n\treturn dget(DEFAULT_PREFERENCES, key) !== undefined;\n}\nexport function coerce(key: string, value: unknown) {\n\tconst type = typeof dget(DEFAULT_PREFERENCES, key);\n\t// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check\n\tswitch (type) {\n\t\tcase 'string':\n\t\t\treturn value;\n\t\tcase 'number':\n\t\t\treturn Number(value);\n\t\tcase 'boolean': {\n\t\t\tif (value === 'true' || value === 1) return true;\n\t\t\tif (value === 'false' || value === 0) return false;\n\t\t\tbreak;\n\t\t}\n\t\tdefault:\n\t\t\tthrow new Error(`Incorrect value for ${key}`);\n\t}\n\treturn value as any;\n}\n\nexport default function createPreferences(\n\tconfig: Record<string, any>,\n\tdotAstroDir: URL,\n): AstroPreferences {\n\tconst global = new PreferenceStore(getGlobalPreferenceDir());\n\tconst project = new PreferenceStore(fileURLToPath(dotAstroDir));\n\tconst stores: Record<PreferenceLocation, PreferenceStore> = { global, project };\n\n\treturn {\n\t\tasync get(key, { location } = {}) {\n\t\t\tif (!location) return project.get(key) ?? global.get(key) ?? dget(DEFAULT_PREFERENCES, key);\n\t\t\treturn stores[location].get(key);\n\t\t},\n\t\tasync set(key, value, { location = 'project', reloadServer = true } = {}) {","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/withastro/astro/blob/d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca/packages/astro/src/preferences/index.ts#L60-L96","documentation":"When deserializing a stored preference, Astro coerces the stored string to the preference's declared type via a switch. It handles `'string'`, `'number'`, and `'boolean'` (boolean accepts `'true'`/`1` and `'false'`/`0`). Any other type, or a boolean value that isn't one of those four accepted literals, falls through to the `default` branch and throws a plain `Incorrect value for ${key}` Error.","triggerScenarios":"A preference declared with a type other than string/number/boolean, or a boolean preference whose stored value is something other than `'true'`, `'false'`, `1`, or `0` (e.g. corrupted store, manually edited `.astro` preferences file).","commonSituations":"Manually editing the `.astro/preferences.json` (or global preferences) file and writing an invalid boolean like `'yes'` or `1.0`; a preferences schema entry with an unsupported type field; corruption from a partial write or version downgrade.","solutions":["Reset the offending preference by deleting its entry (or the whole preferences store) so Astro re-creates it with a valid value.","Ensure boolean preferences store only `'true'`/`'false'`/`1`/`0`; for other types use string or number.","Avoid hand-editing the preferences file; use the preferences API."],"exampleFix":"// before — manually edited .astro/preferences.json has\n// { \"featureFlags.x\": { type: \"boolean\", value: \"yes\" } }  -> throws\n\n// after — valid boolean literal\n// { \"featureFlags.x\": { type: \"boolean\", value: \"true\" } }","handlingStrategy":"validation","validationCode":"function isValidStoredBoolean(value) {\n  return value === 'true' || value === 'false' || value === 1 || value === 0;\n}\nfunction isValidPrefType(type) {\n  return type === 'string' || type === 'number' || type === 'boolean';\n}","typeGuard":"function isValidPrefEntry(entry) {\n  return entry &&\n    ['string','number','boolean'].includes(entry.type) &&\n    (entry.type !== 'boolean' || ['true','false',1,0].includes(entry.value));\n}","tryCatchPattern":"null","preventionTips":["Do not hand-edit the .astro preferences file; use the preferences API.","For booleans, store only 'true'/'false' (or 1/0).","Delete a corrupted preferences store to let Astro rebuild it."],"tags":["preferences","config","serialization"],"backgroundTag":null,"analyzedSha":"d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca","analyzedAt":"2026-08-12T13:37:29.035Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}