{"record":{"id":"1bbda8327faad385","repo":"langgenius/dify","slug":"name-must-contain-non-empty-strings","errorCode":null,"errorMessage":"${name} must contain non-empty strings","messagePattern":"(.+?) must contain non-empty strings","errorType":"validation","errorClass":"ValidationError","httpStatus":null,"severity":"error","filePath":"sdks/nodejs-client/src/client/validation.ts","lineNumber":63,"sourceCode":"export function ensureOptionalBoolean(value: unknown, name: string): void {\n  if (value === undefined || value === null) {\n    return\n  }\n  if (typeof value !== 'boolean') {\n    throw new ValidationError(`${name} must be a boolean when set`)\n  }\n}\n\nexport function ensureStringArray(value: unknown, name: string): void {\n  if (!Array.isArray(value) || value.length === 0) {\n    throw new ValidationError(`${name} must be a non-empty string array`)\n  }\n  if (value.length > MAX_LIST_LENGTH) {\n    throw new ValidationError(`${name} exceeds maximum size of ${MAX_LIST_LENGTH} items`)\n  }\n  value.forEach((item) => {\n    if (typeof item !== 'string' || item.trim().length === 0) {\n      throw new ValidationError(`${name} must contain non-empty strings`)\n    }\n  })\n}\n\nexport function ensureOptionalStringArray(value: unknown, name: string): void {\n  if (value === undefined || value === null) {\n    return\n  }\n  ensureStringArray(value, name)\n}\n\nexport function ensureRating(value: unknown): void {\n  if (value === undefined || value === null) {\n    return\n  }\n  if (value !== 'like' && value !== 'dislike') {\n    throw new ValidationError(\"rating must be either 'like' or 'dislike'\")\n  }","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/sdks/nodejs-client/src/client/validation.ts#L45-L81","documentation":"Thrown by ensureStringArray() in validation.ts:63 as a ValidationError. After the array is confirmed non-empty and within the size cap, each item is checked: every element must be a string of length ≥ 1 after trim. A single empty/whitespace item or a non-string element fails the whole call.","triggerScenarios":"Calling kb.listDatasets({ tagIds: ['tag-1', '', 'tag-3'] }) (one empty), { tagIds: ['tag-1', 42] } (non-string), { tagIds: ['   '] } (whitespace). The forEach at validation.ts:61 throws on the offending item.","commonSituations":"Mapping objects to ids where some rows have no id (producing undefined then stringified to 'undefined' or filtered to ''); splitting a comma string that yields empty tokens ('a,,b'); mixed-type arrays from untyped JSON.","solutions":["Filter before sending: tagIds.filter((t): t is string => typeof t === 'string' && t.trim().length > 0).","Validate each id at the source rather than relying on the SDK to reject the batch.","Use a Set to dedupe after filtering."],"exampleFix":"// before\nawait kb.listDatasets({ tagIds: raw.split(',') }) // 'a,,b' -> ['a','','b']\n\n// after\nconst tagIds = raw.split(',').map(s => s.trim()).filter(Boolean)\nif (tagIds.length) await kb.listDatasets({ tagIds })","handlingStrategy":"validation","validationCode":"function cleanStringArray(value: unknown): string[] {\n  if (!Array.isArray(value)) return []\n  return value.filter((v): v is string => typeof v === 'string' && v.trim().length > 0)\n}","typeGuard":"function isCleanStringArray(value: unknown): value is string[] {\n  return Array.isArray(value) && value.every((v) => typeof v === 'string' && v.trim().length > 0)\n}","tryCatchPattern":"try {\n  await kb.listDatasets({ tagIds })\n} catch (err) {\n  if (err instanceof Error && /must contain non-empty strings/.test(err.message)) {\n    const clean = (tagIds as unknown[]).filter((v): v is string => typeof v === 'string' && v.trim().length > 0)\n    if (clean.length) await kb.listDatasets({ tagIds: clean })\n  } else throw err\n}","preventionTips":["Map+filter lists from untyped sources before sending.","Deduplicate with a Set after filtering.","Reject mixed-type arrays in your schema validation."],"tags":["validation","array","string-array","items","filtering"],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}