{"record":{"id":"706edb6a255c13de","repo":"ruvnet/RuView","slug":"guidance-topic-must-be-a-string-706edb","errorCode":null,"errorMessage":"guidance topic must be a string","messagePattern":"guidance topic must be a string","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"harness/ruview/src/guidance.js","lineNumber":348,"sourceCode":" *   recommendedCommands: string[],\n *   relatedKnowledge: object[],\n *   sourceCheck: object,\n *   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  }","sourceCodeStart":330,"sourceCodeEnd":366,"githubUrl":"https://github.com/ruvnet/RuView/blob/4685618388a5e49fad5b3005806f3bdd6a7c25c3/harness/ruview/src/guidance.js#L330-L366","documentation":"getGuidance() requires input.topic to be a string when present. Only undefined is treated as absent (defaulting to 'overview'); null, numbers, arrays, or any non-string throw this TypeError before the topic allowlist check.","triggerScenarios":"getGuidance({ topic: null }) (null is not undefined, so it throws), getGuidance({ topic: 5 }), getGuidance({ topic: ['overview'] }), or a CLI flag parsed as a number/boolean landing in topic.","commonSituations":"Passing null to mean 'use the default' — this API uses undefined/omission for that; argument parsers that coerce flags; a caller sending topic from untyped JSON input.","solutions":["Omit the topic field or pass undefined to get the 'overview' default.","Coerce known-safe input: topic: typeof raw === 'string' ? raw : undefined.","Check the value before calling: if (topic !== undefined && typeof topic !== 'string') throw or normalize."],"exampleFix":"// before\ngetGuidance({ topic: null }) // TypeError: guidance topic must be a string\n// after\ngetGuidance({}) // topic defaults to 'overview'","handlingStrategy":"type-guard","validationCode":"if (topic !== undefined && typeof topic !== 'string') {\n  topic = undefined; // or fail loudly with your own error\n}\ngetGuidance({ topic });","typeGuard":"function isOptionalString(v) {\n  return v === undefined || typeof v === 'string';\n}","tryCatchPattern":"try {\n  getGuidance({ topic });\n} catch (e) {\n  if (e instanceof TypeError && e.message === 'guidance topic must be a string') {\n    return getGuidance({}); // fall back to default topic 'overview'\n  }\n  throw e;\n}","preventionTips":["Use omission/undefined for defaults; this API does not treat null as absent.","Type the boundary (JSDoc/TS) so topic is string | undefined.","Normalize untyped CLI/env values with typeof checks before passing them in."],"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"}