{"record":{"id":"d71421701217353a","repo":"JuliusBrussee/caveman","slug":"filter-key-must-be-a-non-empty-array-of-non-empty-strings","errorCode":null,"errorMessage":"filter ${key} must be a non-empty array of non-empty strings","messagePattern":"filter (.+?) must be a non-empty array of non-empty strings","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/agent-mcp.ts","lineNumber":472,"sourceCode":"    \"model\",\n    \"provider\",\n    \"error_code\",\n    \"auth_mode\",\n    \"runtime_mode\",\n    \"cache_status\",\n    \"session_id\",\n    \"client_user_hash\",\n    \"trace_id\",\n    \"member_user_id\",\n    \"api_key_id\",\n    \"optimization_id\",\n    \"status_class\",\n  ];\n  for (const key of stringListKeys) {\n    const value = filters[key];\n    if (value === undefined) continue;\n    if (!Array.isArray(value) || value.length === 0 || value.some((entry) => typeof entry !== \"string\" || entry.trim() === \"\")) {\n      throw new Error(`filter ${key} must be a non-empty array of non-empty strings`);\n    }\n    if (key === \"status_class\" && value.some((entry) => ![\"2xx\", \"4xx\", \"5xx\"].includes(entry as string))) {\n      throw new Error(\"filter status_class values must be 2xx, 4xx, or 5xx\");\n    }\n  }\n  for (const key of [\"min_cost_usd\", \"max_cost_usd\", \"min_total_tokens\", \"max_total_tokens\", \"min_latency_ms\", \"max_latency_ms\"]) {\n    const value = filters[key];\n    if (value !== undefined && (typeof value !== \"number\" || !Number.isFinite(value))) {\n      throw new Error(`filter ${key} must be a finite number`);\n    }\n  }\n  for (const key of [\"has_error\", \"compressed\"]) {\n    const value = filters[key];\n    if (value !== undefined && typeof value !== \"boolean\") throw new Error(`filter ${key} must be a boolean`);\n  }\n  const monitor = filters.monitor;\n  if (monitor !== undefined) {\n    if (!monitor || typeof monitor !== \"object\" || Array.isArray(monitor)) throw new Error(\"filter monitor must be an object\");","sourceCodeStart":454,"sourceCodeEnd":490,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/cli/src/agent-mcp.ts#L454-L490","documentation":"For list-typed filter keys (workflow, agent, model, provider, error_code, status_class, ...), validateTraceFilters requires the value to be a non-empty array whose every element is a non-empty string. A missing key is fine (undefined is skipped), but a wrong shape, an empty array, or an empty/whitespace/non-string element throws this error.","triggerScenarios":"Passing filters like { workflow: 'deploy' } (string instead of array), { agent: [] } (empty array), { model: ['gpt-4', ''] } (empty string element), or { provider: [123] } (non-string element).","commonSituations":"Clients passing a single value instead of an array; trimming leading to empty strings; serializers turning empty filters into []; numeric ids passed without string conversion.","solutions":["Wrap single values in an array: workflow: ['deploy']","Ensure the array is non-empty — drop the key entirely if there are no values","Filter/trim entries and remove empties before sending","Convert non-string entries to strings or drop them"],"exampleFix":"// before\nsearchTraces({ filters: { workflow: 'deploy' } });\nsearchTraces({ filters: { agent: [] } });\n// after\nsearchTraces({ filters: { workflow: ['deploy'] } });\n// omit agent entirely when empty","handlingStrategy":"validation","validationCode":"function assertStringList(filters, key) {\n  const v = filters?.[key];\n  if (v === undefined) return;\n  if (!Array.isArray(v) || v.length === 0 || v.some((e) => typeof e !== 'string' || e.trim() === '')) {\n    throw new Error(`filter ${key} must be a non-empty array of non-empty strings`);\n  }\n}","typeGuard":"function isNonEmptyStringArray(v) {\n  return Array.isArray(v) && v.length > 0 && v.every((e) => typeof e === 'string' && e.trim() !== '');\n}","tryCatchPattern":"try {\n  await searchTraces({ filters });\n} catch (error) {\n  const m = error.message.match(/^filter (\\w+) must be a non-empty array/);\n  if (m) {\n    const v = filters[m[1]];\n    filters[m[1]] = typeof v === 'string' ? [v] : (v ?? []).map(String).filter((s) => s.trim());\n  }\n}","preventionTips":["Always wrap single values in an array before sending list filters","Omit the key entirely instead of passing []","Trim and drop empty entries before sending","Coerce non-string entries with String() or drop them"],"tags":["mcp","validation","traces","filters"],"backgroundTag":"invalid-argument-format","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"}