{"record":{"id":"cd2644807dc0e864","repo":"ruvnet/RuView","slug":"guidance-query-must-be-a-string-cd2644","errorCode":null,"errorMessage":"guidance query must be a string","messagePattern":"guidance query must be a string","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"harness/ruview/src/guidance.js","lineNumber":351,"sourceCode":" *   authority: string\n * }} Structured guidance suitable for CLI or MCP serialization.\n * @throws {TypeError|RangeError} When called directly with malformed input.\n *\n * @example\n * getGuidance({ topic: 'homecore', query: 'Wasmtime plugin' });\n */\nexport function getGuidance(input = {}, options = {}) {\n  if (!input || typeof input !== 'object' || Array.isArray(input)) {\n    throw new TypeError('guidance input must be an object');\n  }\n  if (!options || typeof options !== 'object' || Array.isArray(options)) {\n    throw new TypeError('guidance options must be an object');\n  }\n  if (input.topic !== undefined && typeof input.topic !== 'string') {\n    throw new TypeError('guidance topic must be a string');\n  }\n  if (input.query !== undefined && typeof input.query !== 'string') {\n    throw new TypeError('guidance query must be a string');\n  }\n  if (input.limit !== undefined && (typeof input.limit !== 'number' || !Number.isFinite(input.limit))) {\n    throw new TypeError('guidance limit must be a finite number');\n  }\n  if (options.repoRoot !== undefined && options.repoRoot !== null && typeof options.repoRoot !== 'string') {\n    throw new TypeError('guidance repoRoot must be a string or null');\n  }\n  const topic = input.topic === undefined ? 'overview' : input.topic;\n  if (!GUIDANCE_TOPICS.includes(topic)) {\n    throw new RangeError(`unsupported guidance topic: ${topic}`);\n  }\n  const query = input.query === undefined ? '' : input.query.trim();\n  if (query && (query.length < 2 || query.length > 500)) {\n    throw new RangeError('guidance query must contain 2..500 characters');\n  }\n  const rawLimit = input.limit === undefined ? 20 : input.limit;\n  if (!Number.isFinite(rawLimit) || rawLimit < 1 || rawLimit > 20) {\n    throw new RangeError('guidance limit must be between 1 and 20');","sourceCodeStart":333,"sourceCodeEnd":369,"githubUrl":"https://github.com/ruvnet/RuView/blob/4685618388a5e49fad5b3005806f3bdd6a7c25c3/harness/ruview/src/guidance.js#L333-L369","documentation":"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.","triggerScenarios":"getGuidance({ query: null }), getGuidance({ query: 42 }), getGuidance({ query: ['Wasmtime'] }), or forwarding a search box's numeric/empty value without a typeof check.","commonSituations":"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.","solutions":["Omit the query field or pass undefined when there is no search term.","Coerce: query: typeof rawQuery === 'string' ? rawQuery : undefined.","Validate before the call: if (query !== undefined && typeof query !== 'string') normalize or reject."],"exampleFix":"// before\ngetGuidance({ topic: 'homecore', query: null })\n// after\ngetGuidance({ topic: 'homecore', query: 'Wasmtime plugin' }) // or omit query","handlingStrategy":"type-guard","validationCode":"if (query !== undefined && typeof query !== 'string') {\n  query = undefined;\n}\ngetGuidance({ query });","typeGuard":"function isOptionalQuery(v) {\n  return v === undefined || (typeof v === 'string' && v.trim().length >= 2 && v.trim().length <= 500);\n}","tryCatchPattern":"try {\n  getGuidance({ query });\n} catch (e) {\n  if (e instanceof TypeError && e.message === 'guidance query must be a string') {\n    return getGuidance({}); // proceed without a query\n  }\n  throw e;\n}","preventionTips":["Pass search terms as strings; omit the key for no search.","Never use null for optional fields in this API.","Where queries come from form inputs, coerce to string and trim first."],"tags":["validation","guidance","typeerror","ruview-harness"],"backgroundTag":null,"analyzedSha":"4685618388a5e49fad5b3005806f3bdd6a7c25c3","analyzedAt":"2026-08-16T06:09:40.886Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}