ruvnet/RuView · error · RangeError

guidance limit must be between 1 and 20

Error message

guidance limit must be between 1 and 20

What it means

getGuidance clamps result size to 1..20 capabilities. input.limit defaults to 20; values below 1, above 20, or non-finite (NaN/Infinity sneak past the earlier type check only via defaulting) throw this RangeError. Fractional values like 5.5 are floored and accepted.

Source

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

    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);
  const candidates = CAPABILITIES
    .filter((capability) => topic === 'overview' || capability.topics.includes(topic))
    .map((capability, order) => ({ capability, order, score: scoreCapability(capability, wanted) }))
    .filter(({ score }) => score > 0)
    .sort((a, b) => b.score - a.score || a.order - b.order)
    .slice(0, limit)
    .map(({ capability }) => ({
      ...capability,
      topics: [...capability.topics],
      sources: [...capability.sources],
      validation: [...capability.validation],
      limitations: [...capability.limitations],
    }));

  const root = options.repoRoot ? resolve(options.repoRoot) : null;

View on GitHub (pinned to 4685618388)

Solutions

  1. Clamp before calling: limit: Math.min(20, Math.max(1, limit)).
  2. Omit limit to accept the default maximum of 20.
  3. If you truly need more coverage, iterate over topics (overview + specific topics) instead of raising the limit.

Example fix

// before
getGuidance({ topic: 'overview', limit: 100 }) // RangeError: guidance limit must be between 1 and 20
// after
const limit = Math.min(20, Math.max(1, Number(rawLimit) || 20));
getGuidance({ topic: 'overview', limit });
Defensive patterns

Strategy: validation

Validate before calling

const limit = rawLimit === undefined ? 20 : Math.min(20, Math.max(1, Math.floor(Number(rawLimit))));
if (!Number.isFinite(limit)) throw new Error('limit must be numeric');
getGuidance({ limit });

Type guard

function isValidGuidanceLimit(v) {
  return v === undefined || (typeof v === 'number' && Number.isFinite(v) && v >= 1 && v <= 20);
}

Try / catch

try {
  getGuidance({ limit });
} catch (e) {
  if (e instanceof RangeError && e.message.includes('between 1 and 20')) {
    return getGuidance({ limit: 20 });
  }
  throw e;
}

Prevention

When it happens

Trigger: getGuidance({ limit: 0 }) (often meant as 'default'), { limit: 100 } ('give me everything'), { limit: -1 }; numeric limits parsed from config that also produce NaN via the defaulting path.

Common situations: Asking for all capabilities with a large limit; using 0 or -1 as an 'unlimited' sentinel from another API's convention; copying a limit of 50 from a different tool's CLI.

Related errors


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