hcengineering/platform · error
Invalid duration format
Error message
Invalid duration format
What it means
parseLookbackDuration parses a user-supplied duration string (e.g. "7d") used to limit the navigator's card lookback window. It throws 'Invalid duration format' when the input is shorter than 2 characters, since it requires at least one numeric character plus a unit suffix. It is an input-format validation error.
Source
Thrown at plugins/card-resources/src/components/navigator-next/NavigatorCardsSection.svelte:52
export let selectedCard: Ref<Card> | undefined = undefined
const cardsQuery = createQuery()
const notificationContextsQuery = createNotificationContextsQuery()
let cards: Card[] = []
let contextByCard = new Map<Ref<Card>, NotificationContext>()
let isLoading: boolean = true
let hasMore = false
let sort: 'alphabetical' | 'recent' | undefined
$: sort = config.specialSorting?.[type._id] ?? config.defaultSorting ?? 'alphabetical'
let limit = config.limit
$: ids = (config.labelFilter?.length ?? 0) > 0 ? labels.map((it) => it.cardId) : undefined
function parseLookbackDuration (input: string): Timestamp {
if (input.length < 2) throw new Error('Invalid duration format')
const unit = input.slice(-1)
const numberPart = input.slice(0, -1)
const value = Number(numberPart)
if (isNaN(value) || value <= 0) throw new Error('Invalid numeric value')
const multipliers: Record<string, number> = {
m: 60 * 1000,
h: 60 * 60 * 1000,
d: 24 * 60 * 60 * 1000,
w: 7 * 24 * 60 * 60 * 1000
}
const multiplier = multipliers[unit]
if (!multiplier) throw new Error(`Unsupported time unit: ${unit}`)
View on GitHub (pinned to 63e28dc964)
Solutions
- Provide a full duration string with number and unit, e.g. "7d", "24h", "30m".
- Trim whitespace and re-check the stored config for the lookback key.
- Add UI validation that rejects duration strings shorter than 2 chars before saving.
Example fix
// before config.lookback = 'd' // after config.lookback = '7d'
Defensive patterns
Strategy: validation
Validate before calling
const DURATION_RE = /^\d+[mhdw]$/
if (!DURATION_RE.test(lookback)) { ui.notify('Use a duration like 7d, 24h, 30m'); return } Type guard
function isDurationString(v: unknown): v is `${number}${'m'|'h'|'d'|'w'}` {
return typeof v === 'string' && /^\d+[mhdw]$/.test(v)
} Try / catch
try {
const ts = parseLookbackDuration(config.lookback)
} catch (e) {
if (e instanceof Error && e.message === 'Invalid duration format') {
config.lookback = '7d' // fall back to a safe default
} else throw e
} Prevention
- Validate duration config fields with a regex before saving.
- Use structured inputs (number + unit dropdown) instead of free-text duration strings.
- Always store at least number+unit (length >= 2).
When it happens
Trigger: Configuring the navigator section with a lookback duration like "", "d", or "7" — a string with length < 2.
Common situations: Mistyped configuration values (empty field, unit only), config keys pasted incompletely, or locale-specific entries that drop the number part.
Related errors
- Invalid numeric value
- Unsupported time unit: ${unit}
- No screen access granted
- Accounts url not specified
- Ticks per second has an invalid value: must be >= 1 && <= 10
AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29).
Data as JSON: /api/errors/f9de264c90556b8f.
Report an issue: GitHub.