hcengineering/platform · error

Invalid numeric value

Error message

Invalid numeric value

What it means

parseLookbackDuration converts the numeric prefix of the duration string with Number() and rejects it when the result is NaN or <= 0. This throws 'Invalid numeric value', meaning the string had a unit but the number part was not a positive number.

Source

Thrown at plugins/card-resources/src/components/navigator-next/NavigatorCardsSection.svelte:58

  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}`)

    return value * multiplier
  }

  $: cardIds = ids?.filter((it) => !favorites.some((fav) => fav.attachedTo === it))

  $: if ((cardIds && cardIds.length > 0) || (config.labelFilter?.length ?? 0) === 0) {

View on GitHub (pinned to 63e28dc964)

Solutions

  1. Correct the config to a positive integer with a supported unit, e.g. "14d".
  2. Trim the input and validate with a regex like /^\d+[mhdw]$/ before parsing.
  3. Constrain the settings UI to a numeric input followed by a unit selector.

Example fix

// before
lookback = '-3d'
// after
lookback = '3d'
Defensive patterns

Strategy: validation

Validate before calling

const numberPart = input.slice(0, -1)
const value = Number(numberPart)
if (isNaN(value) || value <= 0) { ui.notify('Duration number must be a positive number, e.g. 7d'); return }

Type guard

function isPositiveNumber(v: string): boolean { const n = Number(v); return !isNaN(n) && n > 0 }

Try / catch

try {
  const ts = parseLookbackDuration(input)
} catch (e) {
  if (e instanceof Error && e.message === 'Invalid numeric value') {
    input = '7d'
  } else throw e
}

Prevention

When it happens

Trigger: Passing values like "xd", "7.5.5h", "-3d", ".d", or " d" where `Number(numberPart)` yields NaN or a non-positive value.

Common situations: Hand-edited config files, copy/paste errors introducing stray characters, accidental negative values, or non-Latin digits pasted from other tools.

Related errors


AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29). Data as JSON: /api/errors/b0f593413d5aaf19. Report an issue: GitHub.