JuliusBrussee/caveman · error

tool catalog names must be non-empty and unique

Error message

tool catalog names must be non-empty and unique

What it means

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.

Solutions

  1. Deduplicate the catalog by name before calling searchTools
  2. Filter out tools with empty/whitespace names
  3. Ensure every CaveTool has a defined string name at registration time
  4. Normalize names once at registration to avoid case/whitespace collisions

Example fix

// before
const catalog = [...pluginTools, ...coreTools]; // may contain duplicates
// after
const seen = new Set();
const catalog = [...pluginTools, ...coreTools].filter(t => t.name?.trim() && !seen.has(t.name) && seen.add(t.name));
Defensive patterns

Strategy: validation

Validate before calling

function sanitizeCatalog(tools: CaveTool[]): CaveTool[] {
  const seen = new Set<string>();
  return tools.filter(t => {
    if (typeof t.name !== "string" || t.name.trim() === "" || seen.has(t.name)) return false;
    seen.add(t.name);
    return true;
  });
}
const cleanCatalog = sanitizeCatalog(catalog);

Type guard

function hasValidUniqueNames(tools: CaveTool[]): boolean {
  const names = new Set<string>();
  for (const t of tools) {
    if (typeof t.name !== "string" || t.name.trim() === "" || names.has(t.name)) return false;
    names.add(t.name);
  }
  return true;
}

Try / catch

try {
  return await searchTools(cave, catalog, query);
} catch (e) {
  if (/non-empty and unique/.test(e.message)) return searchTools(cave, sanitizeCatalog(catalog), query);
  throw e;
}

Prevention

When it happens

Trigger: Catalog contains two tools with the same name, a tool with name: "" or whitespace-only, or a tool whose name is undefined/null.

Common situations: Merging tool lists from multiple sources that overlap; auto-generated tools with missing names; trimming/normalization creating duplicates after registration.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/59923e0f7ce2feb2. Report an issue: GitHub.

Appendix: source

Thrown at packages/sdk/typescript/src/index.ts:1626

  if (!response.ok) {
    discardResponse(response);
    throw new Error(`tool search failed with HTTP ${response.status}`);
  }
  const data = await response.json();

  // Map snake_case response to camelCase
  const rawSent = strictNonNegativeInt(data.sent_schema_tokens);
  const rawFull = strictNonNegativeInt(data.full_schema_tokens);
  const validCounts = rawSent !== null && rawFull !== null && rawSent <= rawFull;
  const sentSchemaTokens = validCounts ? rawSent : 0;
  const fullSchemaTokens = validCounts ? rawFull : 0;
  const savedTokens = fullSchemaTokens - sentSchemaTokens;
  const reductionPct = fullSchemaTokens === 0 ? 0 : Math.round((savedTokens / fullSchemaTokens) * 1000) / 10;

  const catalogByName = new Map<string, CaveTool>();
  for (const tool of catalog) {
    if (typeof tool.name !== "string" || tool.name.trim() === "" || catalogByName.has(tool.name)) {
      throw new Error("tool catalog names must be non-empty and unique");
    }
    catalogByName.set(tool.name, tool);
  }
  if (!Array.isArray(data.tools)) throw new Error("tool search response tools must be an array");
  const returnedNames = new Set<string>();
  const selectedTools = data.tools.map((wire: unknown) => {
    const name = wire !== null && typeof wire === "object" && typeof (wire as Record<string, unknown>)["name"] === "string"
      ? (wire as Record<string, unknown>)["name"] as string
      : "";
    const local = catalogByName.get(name);
    if (!local || returnedNames.has(name)) throw new Error("tool search response contained an unknown or duplicate tool");
    returnedNames.add(name);
    return local;
  });

  return {
    sessionId: typeof data.session_id === "string" ? data.session_id : undefined,
    tools: selectedTools,

View on GitHub (pinned to 3ee70a1026)