google-gemini/gemini-cli · error
Invalid retention period format: ${period}. Expected format:
Error message
Invalid retention period format: ${period}. Expected format: <number><unit> where unit is h, d, w, or m What it means
Thrown by parseRetentionPeriod when a retention-period string does not match the regex /^(\d+)([dhwm])$/ — i.e. it is not <digits> followed by exactly one of h/d/w/m. Used by the session cleanup feature to convert human-friendly periods (e.g. 30d, 24h) into milliseconds via MULTIPLIERS.
Source
Thrown at packages/cli/src/utils/sessionCleanup.ts:392
}
}
if (shouldDelete) {
sessionsToDelete.push(entry);
}
}
return sessionsToDelete;
}
/**
* Parses retention period strings like "30d", "7d", "24h" into milliseconds
* @throws {Error} If the format is invalid
*/
function parseRetentionPeriod(period: string): number {
const match = period.match(/^(\d+)([dhwm])$/);
if (!match) {
throw new Error(
`Invalid retention period format: ${period}. Expected format: <number><unit> where unit is h, d, w, or m`,
);
}
const value = parseInt(match[1], 10);
const unit = match[2];
// Reject zero values as they're semantically invalid
if (value === 0) {
throw new Error(
`Invalid retention period: ${period}. Value must be greater than 0`,
);
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
return value * MULTIPLIERS[unit as keyof typeof MULTIPLIERS];
}
View on GitHub (pinned to 5024443c72)
Solutions
- Use the exact format <number><unit> with a lowercase unit: h, d, w, or m — e.g. '24h', '30d', '2w', '6m'.
- Trim/normalize the value before passing it; ensure no surrounding whitespace or quotes.
- If exposing this in a UI, validate against the same regex and reject invalid input before saving.
Example fix
// before // retention: '30 days' // after // retention: '30d'
Defensive patterns
Strategy: validation
Validate before calling
function isValidRetentionPeriod(period) {
return /^(\d+)([dhwm])$/.test(period);
}
// Use before storing/applying the value.
if (!isValidRetentionPeriod(userInput)) {
throw new Error('Retention must be like 24h, 30d, 2w, or 6m');
} Type guard
const isRetentionPeriodString = (v) => typeof v === 'string' && /^(\d+)([dhwm])$/.test(v);
Prevention
- Validate retention strings at the config-load boundary with the same regex.
- Provide a dropdown of valid units in any UI that collects retention.
When it happens
Trigger: parseRetentionPeriod(period) receives a string failing the regex: contains letters other than the unit (e.g. '30 days'), wrong unit (e.g. '30s'), non-numeric value (e.g. 'abc'), missing unit (e.g. '30'), extra characters, or whitespace.
Common situations: User sets a cleanup retention config value like '30 days' or '1 month' (full word) instead of '30d'/'1m'. Typos such as '30D' (uppercase not matched) or '30day'. Empty string. Value loaded from a config file with surrounding quotes or whitespace.
Related errors
- Invalid regex pattern in allowedExtensions setting: "${patte
- Invalid retention period: ${period}. Value must be greater t
- Invalid session ID "${trimmed}": Only alphanumeric character
- Invalid approval mode: ${rawApprovalMode}. Valid values are:
- Invalid telemetry configuration: ${err.message}.
AI-assisted analysis of google-gemini/gemini-cli@5024443c72 (2026-08-12).
Data as JSON: /api/errors/75d0314d1f2f8686.
Report an issue: GitHub.