ruvnet/RuView · error · TypeError

guidance query must be a string

Error message

guidance query must be a string

What it means

getGuidance() requires input.query to be a string when present. undefined means 'no query'; null, numbers, arrays, or objects throw this TypeError before the 2..500 length check runs.

Source

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

 *   authority: string
 * }} Structured guidance suitable for CLI or MCP serialization.
 * @throws {TypeError|RangeError} When called directly with malformed input.
 *
 * @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');

View on GitHub (pinned to 4685618388)

Solutions

  1. Omit the query field or pass undefined when there is no search term.
  2. Coerce: query: typeof rawQuery === 'string' ? rawQuery : undefined.
  3. Validate before the call: if (query !== undefined && typeof query !== 'string') normalize or reject.

Example fix

// before
getGuidance({ topic: 'homecore', query: null })
// after
getGuidance({ topic: 'homecore', query: 'Wasmtime plugin' }) // or omit query
Defensive patterns

Strategy: type-guard

Validate before calling

if (query !== undefined && typeof query !== 'string') {
  query = undefined;
}
getGuidance({ query });

Type guard

function isOptionalQuery(v) {
  return v === undefined || (typeof v === 'string' && v.trim().length >= 2 && v.trim().length <= 500);
}

Try / catch

try {
  getGuidance({ query });
} catch (e) {
  if (e instanceof TypeError && e.message === 'guidance query must be a string') {
    return getGuidance({}); // proceed without a query
  }
  throw e;
}

Prevention

When it happens

Trigger: getGuidance({ query: null }), getGuidance({ query: 42 }), getGuidance({ query: ['Wasmtime'] }), or forwarding a search box's numeric/empty value without a typeof check.

Common situations: Using null to express 'no search term' instead of omitting the key; passing a URLSearchParams object or array from a form handler; untyped JSON input where query arrived as a number.

Related errors


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