{"record":{"id":"1ac00b4412786c65","repo":"withastro/astro","slug":"key-expects-a-defaulttype-value","errorCode":null,"errorMessage":"${key} expects a \"${defaultType}\" value!","messagePattern":"(.+?) expects a \"(.+?)\" value!","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/astro/src/cli/preferences/index.ts","lineNumber":168,"sourceCode":"\t\t\treturn 0;\n\t\t}\n\t\tlogger.info('SKIP_FORMAT', msg.preferenceGet(key, value));\n\t\treturn 0;\n\t} catch {}\n\treturn 1;\n}\n\nasync function setPreference(\n\tsettings: AstroSettings,\n\tlogger: AstroLogger,\n\tkey: PreferenceKey,\n\tvalue: unknown,\n\t{ location }: SubcommandOptions,\n) {\n\ttry {\n\t\tconst defaultType = typeof dlv(DEFAULT_PREFERENCES, key);\n\t\tif (typeof coerce(key, value) !== defaultType) {\n\t\t\tthrow new Error(`${key} expects a \"${defaultType}\" value!`);\n\t\t}\n\n\t\tawait settings.preferences.set(key, coerce(key, value), { location });\n\t\tlogger.info('SKIP_FORMAT', msg.preferenceSet(key, value));\n\t\treturn 0;\n\t} catch (e) {\n\t\tif (e instanceof Error) {\n\t\t\tlogger.error('preferences', msg.formatErrorMessage(collectErrorMetadata(e), true));\n\t\t\treturn 1;\n\t\t}\n\t\tthrow e;\n\t}\n}\n\nasync function enablePreference(\n\tsettings: AstroSettings,\n\tlogger: AstroLogger,\n\tkey: PreferenceKey,","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/withastro/astro/blob/e294953aa8aadd98d5be92e60a03037b05dbdfd4/packages/astro/src/cli/preferences/index.ts#L150-L186","documentation":"`astro preferences set <key> <value>` type-checks the coerced value against the type of the key's default in DEFAULT_PREFERENCES. CLI arguments arrive as strings; `coerce(key, value)` converts them (e.g. 'true' -> true for boolean keys). If the coerced result's typeof still does not match the default's typeof, the set is rejected before anything is persisted.","triggerScenarios":"`astro preferences set devToolbar.enabled maybe` (boolean key, uncoercible string); setting a numeric key to non-numeric text; passing extra positional tokens so the wrong value lands in `value`.","commonSituations":"Passing free-text where a boolean/number is expected, quoting mistakes that empty the value, wrong key names whose defaults have a different type than assumed, scripted calls forwarding flags as values.","solutions":["Look up the key and its expected type: `astro preferences list` shows keys and defaults","Pass a value of the matching type: `astro preferences set devToolbar.enabled true` (booleans) or `astro preferences set telemetry.enabled false`","Quote multi-word values properly and make sure you are not accidentally passing a flag as the value"],"exampleFix":"# before\nastro preferences set devToolbar.enabled maybe   # devToolbar.enabled expects a \"boolean\" value!\n\n# after\nastro preferences set devToolbar.enabled true","handlingStrategy":"validation","validationCode":"// inspect the key's default type before setting it\nimport { execSync } from 'node:child_process';\n\nfunction expectedType(key) {\n  const listing = execSync('astro preferences list', { encoding: 'utf8' });\n  const row = listing.split('\\n').find((l) => l.includes(key));\n  return /true|false/.test(row) ? 'boolean' : 'string';\n}\n\nif (typeof value !== expectedType(key)) {\n  // coerce or reject before calling `astro preferences set`\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run `astro preferences list` once to learn each key's type before scripting `set` commands","Pass booleans as the literals true/false and numbers unparsed — never free text","Quote shell arguments so values with spaces are not split into extra positionals"],"tags":["cli","preferences","type-mismatch","configuration"],"backgroundTag":"config-value-type-mismatch","analyzedSha":"e294953aa8aadd98d5be92e60a03037b05dbdfd4","analyzedAt":"2026-08-18T18:48:03.901Z","contentChangedAt":"2026-08-18T18:48:03.901Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}