shadcn-ui/ui · error · RangeError

count must be a non-negative integer.

Error message

count must be a non-negative integer.

What it means

chat.get(count) validates its optional count argument with Number.isInteger and a >= 0 check, throwing a RangeError otherwise. The count caps how many scripted messages are returned from the transcript; get() takes a number, not an options object.

Source

Thrown at packages/helpers/src/core/chat.ts:729

        delayMs,
        phase: "before-start",
      })

      return api
    },

    get(count) {
      const deferredIndex = turns.findIndex(
        (turn) => turn.resolve !== undefined
      )
      const limit = deferredIndex === -1 ? turns.length : deferredIndex

      if (count === undefined) {
        count = limit
      }

      if (!Number.isInteger(count) || count < 0) {
        throw new RangeError("count must be a non-negative integer.")
      }

      if (deferredIndex !== -1 && count > deferredIndex) {
        throw new Error(
          "get() cannot materialize a continuation turn without a live transcript."
        )
      }

      return turns
        .slice(0, count)
        .map((turn) => cloneValue(turn.message as MESSAGE))
    },

    next(messages) {
      const turn = findNextUserTurn(messages)

      return turn?.message ? cloneValue(turn.message) : null
    },

View on GitHub (pinned to efac598707)

Solutions

  1. Pass an explicit non-negative integer, or omit count to get all non-deferred turns.
  2. Clamp computed counts with Math.max(0, Math.floor(n)).
  3. If you meant options, note get() takes a number directly.

Example fix

// before
chat.get(-1)           // throws RangeError
chat.get(1.5)          // throws RangeError
chat.get({ count: 1 }) // throws RangeError

// after
chat.get(0)
chat.get(1)
chat.get()             // all available turns
Defensive patterns

Strategy: validation

Validate before calling

function safeGet(chat, count) {
  if (count === undefined) return chat.get()
  if (!Number.isInteger(count) || count < 0) {
    return [] // or throw a domain error
  }
  return chat.get(count)
}

Type guard

const isNonNegInt = (n: unknown): n is number =>
  typeof n === "number" && Number.isInteger(n) && n >= 0

Try / catch

try {
  chat.get(count)
} catch (e) {
  if (e instanceof RangeError) {
    // fix count and retry, or default to chat.get()
  } else throw e
}

Prevention

When it happens

Trigger: Passing a negative number, a fraction such as 1.5, NaN, or a non-number coerced badly; accidentally passing an options object like get({ count: 1 }).

Common situations: Computed counts from arithmetic that can go negative; off-by-one in slice math; misreading the API as accepting options.

Related errors


AI-assisted analysis of shadcn-ui/ui@efac598707 (2026-08-12). Data as JSON: /api/errors/93dd554814c14d05. Report an issue: GitHub.