upstash/context7 · error · TypeError
timeout must be a positive number or false
Error message
timeout must be a positive number or false
What it means
TypeError thrown by validateTimeout when the `timeout` option is neither `false` (disabled) nor a positive finite number. The SDK requires timeout to be a millisecond value > 0 or explicitly false to disable it.
Source
Thrown at packages/sdk/src/http/abort.ts:11
import { Context7Error } from "@error";
export type AbortState = {
signal?: AbortSignal;
timedOut: () => boolean;
cleanup: () => void;
};
export function validateTimeout(timeout: number | false): void {
if (timeout !== false && (!Number.isFinite(timeout) || timeout <= 0)) {
throw new TypeError("timeout must be a positive number or false");
}
}
export function resolveSignal(signal?: AbortSignal | (() => AbortSignal)): AbortSignal | undefined {
return typeof signal === "function" ? signal() : signal;
}
export function createAbortState(
signals: Array<AbortSignal | undefined>,
timeout: number | false
): AbortState {
validateTimeout(timeout);
const activeSignals = [
...new Set(signals.filter((signal): signal is AbortSignal => signal !== undefined)),
];
if (timeout === false && activeSignals.length === 0) {
return { timedOut: () => false, cleanup: () => undefined };View on GitHub (pinned to 80e681a507)
Solutions
- Pass a positive finite number of milliseconds, e.g. timeout: 10000.
- To disable the timeout entirely, pass timeout: false, not 0.
- If loading from env/config, coerce and validate: Number.isFinite(v) && v > 0 before constructing the client.
- Use Number(rawValue) and guard against NaN when parsing user-supplied values.
Example fix
// before
const client = new Context7Client({ timeout: Number(process.env.TIMEOUT) }); // NaN -> TypeError
// after
const t = Number(process.env.TIMEOUT);
const client = new Context7Client({ timeout: Number.isFinite(t) && t > 0 ? t : false }); Defensive patterns
Strategy: validation
Validate before calling
function assertTimeout(t: unknown): asserts t is number | false {
if (!(t === false || (typeof t === 'number' && Number.isFinite(t) && t > 0))) {
throw new TypeError(`timeout must be a positive number or false, got ${String(t)}`);
}
} Type guard
function isValidTimeout(t: unknown): t is number | false {
return t === false || (typeof t === 'number' && Number.isFinite(t) && t > 0);
} Try / catch
try {
const client = new Context7Client({ timeout: parsedTimeout });
} catch (e) {
if (e instanceof TypeError && /timeout/.test(e.message)) {
console.error('Bad timeout config, falling back to default');
}
throw e;
} Prevention
- Never pass 0 to disable a timeout; use false.
- Coerce env/config values with Number() and check Number.isFinite.
- Centralize timeout parsing in one validated helper.
When it happens
Trigger: Constructing a Context7 client (or calling createAbortState) with timeout: 0, timeout: -1000, timeout: Infinity, timeout: NaN, or a non-number truthy value like a string "5000" that is not false.
Common situations: Loading timeout from environment variables or config files as a string ("5000"), computing it to 0 or NaN via parsing, or intending to disable it with 0 instead of false.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
- Timeouts: ETIMEDOUT, deadlines, and hung requests — what actually expires when a request times out.
Related errors
- Invalid MCP_MAX_SUBSCRIPTIONS; using the default of ${DEFAUL
- invalid_url
- retry.retries must be a non-negative integer
- Request did not return a result
- Request did not return a result
AI-assisted analysis of upstash/context7@80e681a507 (2026-09-08).
Data as JSON: /api/errors/c1d750953fb09342.
Report an issue: GitHub.