withastro/astro · error · Error
expects a " " value!
Error message
${key} expects a "${defaultType}" value! What it means
`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.
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
Example fix
# before astro preferences set devToolbar.enabled maybe # devToolbar.enabled expects a "boolean" value! # after astro preferences set devToolbar.enabled true
Defensive patterns
Strategy: validation
Validate before calling
// inspect the key's default type before setting it
import { execSync } from 'node:child_process';
function expectedType(key) {
const listing = execSync('astro preferences list', { encoding: 'utf8' });
const row = listing.split('\n').find((l) => l.includes(key));
return /true|false/.test(row) ? 'boolean' : 'string';
}
if (typeof value !== expectedType(key)) {
// coerce or reject before calling `astro preferences set`
} Prevention
- 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
When it happens
Trigger: `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`.
Common situations: 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.
Related errors
- Incorrect value for
- Unknown error parsing tsconfig.json or jsconfig.json. Could…
- AdapterSupportOutputMismatch
- Another astro dev server is already running. URL
- Another astro preview server is already running. URL
AI-assisted analysis of withastro/astro@e294953aa8 (2026-08-18).
Data as JSON: /api/errors/1ac00b4412786c65.
Report an issue: GitHub.
Appendix: source
Thrown at packages/astro/src/cli/preferences/index.ts:168
return 0;
}
logger.info('SKIP_FORMAT', msg.preferenceGet(key, value));
return 0;
} catch {}
return 1;
}
async function setPreference(
settings: AstroSettings,
logger: AstroLogger,
key: PreferenceKey,
value: unknown,
{ location }: SubcommandOptions,
) {
try {
const defaultType = typeof dlv(DEFAULT_PREFERENCES, key);
if (typeof coerce(key, value) !== defaultType) {
throw new Error(`${key} expects a "${defaultType}" value!`);
}
await settings.preferences.set(key, coerce(key, value), { location });
logger.info('SKIP_FORMAT', msg.preferenceSet(key, value));
return 0;
} catch (e) {
if (e instanceof Error) {
logger.error('preferences', msg.formatErrorMessage(collectErrorMetadata(e), true));
return 1;
}
throw e;
}
}
async function enablePreference(
settings: AstroSettings,
logger: AstroLogger,
key: PreferenceKey,View on GitHub (pinned to e294953aa8)