{"record":{"id":"864fb740d913d913","repo":"langgenius/dify","slug":"metadata-must-be-one-of-all-only-without","errorCode":null,"errorMessage":"metadata must be one of all, only, without","messagePattern":"metadata must be one of all, only, without","errorType":"validation","errorClass":"ValidationError","httpStatus":null,"severity":"error","filePath":"sdks/nodejs-client/src/client/knowledge-base.ts","lineNumber":295,"sourceCode":"        page: options?.page,\n        limit: options?.limit,\n        keyword: options?.keyword ?? undefined,\n        status: options?.status ?? undefined,\n      },\n    })\n  }\n\n  async getDocument(\n    datasetId: string,\n    documentId: string,\n    options?: DocumentGetOptions,\n  ): Promise<DifyResponse<KnowledgeBaseResponse>> {\n    ensureNonEmptyString(datasetId, 'datasetId')\n    ensureNonEmptyString(documentId, 'documentId')\n    if (options?.metadata) {\n      const allowed = new Set(['all', 'only', 'without'])\n      if (!allowed.has(options.metadata)) {\n        throw new ValidationError('metadata must be one of all, only, without')\n      }\n    }\n    return this.http.request({\n      method: 'GET',\n      path: `/datasets/${datasetId}/documents/${documentId}`,\n      query: {\n        metadata: options?.metadata ?? undefined,\n      },\n    })\n  }\n\n  async deleteDocument(\n    datasetId: string,\n    documentId: string,\n  ): Promise<DifyResponse<KnowledgeBaseResponse>> {\n    ensureNonEmptyString(datasetId, 'datasetId')\n    ensureNonEmptyString(documentId, 'documentId')\n    return this.http.request({","sourceCodeStart":277,"sourceCodeEnd":313,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/sdks/nodejs-client/src/client/knowledge-base.ts#L277-L313","documentation":"Thrown by getDocument() in knowledge-base.ts:295 as a ValidationError when options.metadata is set to a value outside the allowed set {'all','only','without'}. The metadata query param controls whether the response includes document metadata, only metadata, or excludes it.","triggerScenarios":"Calling kb.getDocument(datasetId, documentId, { metadata: 'full' }) or any typo like 'Only' (capitalized), 'with', 'none'. The Set membership check at knowledge-base.ts:294 fails.","commonSituations":"Case mismatch ('All' vs 'all'); assuming additional values like 'full' or 'none'; passing the value from an unvalidated UI dropdown; copy-pasting from API docs that list a different vocabulary.","solutions":["Use one of the three literal lowercase values: kb.getDocument(ds, doc, { metadata: 'all' }).","If the option is optional, omit it entirely rather than passing '' or null.","Constrain the upstream type to a union: metadata?: 'all' | 'only' | 'without' so the compiler rejects typos."],"exampleFix":"// before\nawait kb.getDocument(ds, doc, { metadata: 'Only' })\n\n// after\nawait kb.getDocument(ds, doc, { metadata: 'only' })","handlingStrategy":"validation","validationCode":"const METADATA_OPTIONS = new Set(['all', 'only', 'without'] as const)\nfunction assertMetadataOption(value: unknown) {\n  if (value !== undefined && !METADATA_OPTIONS.has(value as 'all')) {\n    throw new Error(`metadata must be one of all, only, without`)\n  }\n}","typeGuard":"function isMetadataOption(value: unknown): value is 'all' | 'only' | 'without' {\n  return value === 'all' || value === 'only' || value === 'without'\n}","tryCatchPattern":"try {\n  await kb.getDocument(ds, doc, { metadata })\n} catch (err) {\n  if (err instanceof Error && /metadata must be one of/.test(err.message)) {\n    // fall back to no metadata option\n    await kb.getDocument(ds, doc)\n  } else throw err\n}","preventionTips":["Type options.metadata as 'all' | 'only' | 'without' | undefined so the compiler enforces it.","Drive the value from a closed enum in your UI rather than free text.","Lowercase the input before passing: value.toLowerCase() as the option."],"tags":["validation","knowledge-base","enum","document","query-param"],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}