{"record":{"id":"59923e0f7ce2feb2","repo":"JuliusBrussee/caveman","slug":"tool-catalog-names-must-be-non-empty-and-unique","errorCode":null,"errorMessage":"tool catalog names must be non-empty and unique","messagePattern":"tool catalog names must be non-empty and unique","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/sdk/typescript/src/index.ts","lineNumber":1626,"sourceCode":"  if (!response.ok) {\n    discardResponse(response);\n    throw new Error(`tool search failed with HTTP ${response.status}`);\n  }\n  const data = await response.json();\n\n  // Map snake_case response to camelCase\n  const rawSent = strictNonNegativeInt(data.sent_schema_tokens);\n  const rawFull = strictNonNegativeInt(data.full_schema_tokens);\n  const validCounts = rawSent !== null && rawFull !== null && rawSent <= rawFull;\n  const sentSchemaTokens = validCounts ? rawSent : 0;\n  const fullSchemaTokens = validCounts ? rawFull : 0;\n  const savedTokens = fullSchemaTokens - sentSchemaTokens;\n  const reductionPct = fullSchemaTokens === 0 ? 0 : Math.round((savedTokens / fullSchemaTokens) * 1000) / 10;\n\n  const catalogByName = new Map<string, CaveTool>();\n  for (const tool of catalog) {\n    if (typeof tool.name !== \"string\" || tool.name.trim() === \"\" || catalogByName.has(tool.name)) {\n      throw new Error(\"tool catalog names must be non-empty and unique\");\n    }\n    catalogByName.set(tool.name, tool);\n  }\n  if (!Array.isArray(data.tools)) throw new Error(\"tool search response tools must be an array\");\n  const returnedNames = new Set<string>();\n  const selectedTools = data.tools.map((wire: unknown) => {\n    const name = wire !== null && typeof wire === \"object\" && typeof (wire as Record<string, unknown>)[\"name\"] === \"string\"\n      ? (wire as Record<string, unknown>)[\"name\"] as string\n      : \"\";\n    const local = catalogByName.get(name);\n    if (!local || returnedNames.has(name)) throw new Error(\"tool search response contained an unknown or duplicate tool\");\n    returnedNames.add(name);\n    return local;\n  });\n\n  return {\n    sessionId: typeof data.session_id === \"string\" ? data.session_id : undefined,\n    tools: selectedTools,","sourceCodeStart":1608,"sourceCodeEnd":1644,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/sdk/typescript/src/index.ts#L1608-L1644","documentation":"Before mapping the search response, the client validates the local catalog: every tool name must be a non-empty string and unique across the catalog. Duplicate, empty, or non-string names throw this error after the request has already succeeded.","triggerScenarios":"Catalog contains two tools with the same name, a tool with name: \"\" or whitespace-only, or a tool whose name is undefined/null.","commonSituations":"Merging tool lists from multiple sources that overlap; auto-generated tools with missing names; trimming/normalization creating duplicates after registration.","solutions":["Deduplicate the catalog by name before calling searchTools","Filter out tools with empty/whitespace names","Ensure every CaveTool has a defined string name at registration time","Normalize names once at registration to avoid case/whitespace collisions"],"exampleFix":"// before\nconst catalog = [...pluginTools, ...coreTools]; // may contain duplicates\n// after\nconst seen = new Set();\nconst catalog = [...pluginTools, ...coreTools].filter(t => t.name?.trim() && !seen.has(t.name) && seen.add(t.name));","handlingStrategy":"validation","validationCode":"function sanitizeCatalog(tools: CaveTool[]): CaveTool[] {\n  const seen = new Set<string>();\n  return tools.filter(t => {\n    if (typeof t.name !== \"string\" || t.name.trim() === \"\" || seen.has(t.name)) return false;\n    seen.add(t.name);\n    return true;\n  });\n}\nconst cleanCatalog = sanitizeCatalog(catalog);","typeGuard":"function hasValidUniqueNames(tools: CaveTool[]): boolean {\n  const names = new Set<string>();\n  for (const t of tools) {\n    if (typeof t.name !== \"string\" || t.name.trim() === \"\" || names.has(t.name)) return false;\n    names.add(t.name);\n  }\n  return true;\n}","tryCatchPattern":"try {\n  return await searchTools(cave, catalog, query);\n} catch (e) {\n  if (/non-empty and unique/.test(e.message)) return searchTools(cave, sanitizeCatalog(catalog), query);\n  throw e;\n}","preventionTips":["Validate tool names at registration time, not at search time","Deduplicate when merging catalogs from multiple plugins","Trim and normalize names once, centrally"],"tags":["validation","tool-search","catalog","deduplication"],"backgroundTag":"schema-validation-failed","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}