ruvnet/RuView · error · TypeError

guidance limit must be a finite number

Error message

guidance limit must be a finite number

What it means

getGuidance() requires input.limit, when present, to be a finite JavaScript number. Strings like '10', NaN, Infinity, -Infinity, and null (null is not undefined) all fail this TypeError; the later RangeError covers numeric values outside 1..20.

Source

Thrown at harness/ruview/src/guidance.js:354

 *
 * @example
 * getGuidance({ topic: 'homecore', query: 'Wasmtime plugin' });
 */
export function getGuidance(input = {}, options = {}) {
  if (!input || typeof input !== 'object' || Array.isArray(input)) {
    throw new TypeError('guidance input must be an object');
  }
  if (!options || typeof options !== 'object' || Array.isArray(options)) {
    throw new TypeError('guidance options must be an object');
  }
  if (input.topic !== undefined && typeof input.topic !== 'string') {
    throw new TypeError('guidance topic must be a string');
  }
  if (input.query !== undefined && typeof input.query !== 'string') {
    throw new TypeError('guidance query must be a string');
  }
  if (input.limit !== undefined && (typeof input.limit !== 'number' || !Number.isFinite(input.limit))) {
    throw new TypeError('guidance limit must be a finite number');
  }
  if (options.repoRoot !== undefined && options.repoRoot !== null && typeof options.repoRoot !== 'string') {
    throw new TypeError('guidance repoRoot must be a string or null');
  }
  const topic = input.topic === undefined ? 'overview' : input.topic;
  if (!GUIDANCE_TOPICS.includes(topic)) {
    throw new RangeError(`unsupported guidance topic: ${topic}`);
  }
  const query = input.query === undefined ? '' : input.query.trim();
  if (query && (query.length < 2 || query.length > 500)) {
    throw new RangeError('guidance query must contain 2..500 characters');
  }
  const rawLimit = input.limit === undefined ? 20 : input.limit;
  if (!Number.isFinite(rawLimit) || rawLimit < 1 || rawLimit > 20) {
    throw new RangeError('guidance limit must be between 1 and 20');
  }
  const limit = Math.floor(rawLimit);
  const wanted = tokenize(query);

View on GitHub (pinned to 4685618388)

Solutions

  1. Pass a plain number: getGuidance({ limit: 10 }).
  2. Coerce CLI strings: const limit = Number.parseInt(rawLimit, 10); then check Number.isFinite(limit) before calling.
  3. Omit limit entirely to accept the default of 20.

Example fix

// before
getGuidance({ limit: cliFlags.limit }) // cliFlags.limit === '10' (string)
// after
const limit = Number.parseInt(cliFlags.limit, 10);
getGuidance({ limit: Number.isFinite(limit) ? limit : undefined }); // undefined -> default 20
Defensive patterns

Strategy: validation

Validate before calling

const limit = rawLimit === undefined ? undefined : Number(rawLimit);
if (limit !== undefined && !Number.isFinite(limit)) {
  throw new Error(`limit must be a finite number, got ${String(rawLimit)}`);
}
getGuidance({ limit });

Type guard

function isFiniteOptionalNumber(v) {
  return v === undefined || (typeof v === 'number' && Number.isFinite(v));
}

Try / catch

try {
  getGuidance({ limit });
} catch (e) {
  if (e instanceof TypeError && e.message === 'guidance limit must be a finite number') {
    return getGuidance({ limit: 20 });
  }
  throw e;
}

Prevention

When it happens

Trigger: getGuidance({ limit: '10' }), getGuidance({ limit: NaN }), getGuidance({ limit: Infinity }), getGuidance({ limit: null }); typically from CLI args (always strings) or JSON where the producer serialized the number as a string.

Common situations: CLI parsing with yargs/meow without .number('limit'); JSON configs written by hand with quoted numbers; NaN leaking from a division the caller assumed was guarded.

Related errors


AI-assisted analysis of ruvnet/RuView@4685618388 (2026-08-16). Data as JSON: /api/errors/bbf2c5d49fa1bf87. Report an issue: GitHub.