{"record":{"id":"257ff583f7dac1b1","repo":"janhq/jan","slug":"ingestfileattachment-attachment-is-not-document","errorCode":null,"errorMessage":"ingestFileAttachment: attachment is not document","messagePattern":"ingestFileAttachment: attachment is not document","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"web-app/src/services/uploads/default.ts","lineNumber":16,"sourceCode":"import type { UploadsService, UploadResult } from './types'\nimport type { Attachment } from '@/types/attachment'\nimport { ulid } from 'ulidx'\nimport { ExtensionManager } from '@/lib/extension'\nimport { ExtensionTypeEnum, type RAGExtension, type IngestAttachmentsResult } from '@janhq/core'\n\nexport class DefaultUploadsService implements UploadsService {\n  async ingestImage(_threadId: string, attachment: Attachment): Promise<UploadResult> {\n    if (attachment.type !== 'image') throw new Error('ingestImage: attachment is not image')\n    // Placeholder upload flow; swap for real API call when backend is ready\n    await new Promise((r) => setTimeout(r, 100))\n    return { id: ulid() }\n  }\n\n  async ingestFileAttachment(threadId: string, attachment: Attachment): Promise<UploadResult> {\n    if (attachment.type !== 'document') throw new Error('ingestFileAttachment: attachment is not document')\n    const ext = ExtensionManager.getInstance().get<RAGExtension>(ExtensionTypeEnum.RAG)\n    if (!ext?.ingestAttachments) throw new Error('RAG extension not available')\n    const res: IngestAttachmentsResult = await ext.ingestAttachments(threadId, [\n      { path: attachment.path!, name: attachment.name, type: attachment.fileType, size: attachment.size },\n    ])\n    const files = res.files\n    if (Array.isArray(files) && files[0]?.id) {\n      return {\n        id: files[0].id,\n        size: typeof files[0].size === 'number' ? Number(files[0].size) : undefined,\n        chunkCount: typeof files[0].chunk_count === 'number' ? Number(files[0].chunk_count) : undefined,\n      }\n    }\n    throw new Error('Failed to resolve ingested attachment id')\n  }\n\n  async ingestFileAttachmentForProject(projectId: string, attachment: Attachment): Promise<UploadResult> {\n    if (attachment.type !== 'document') throw new Error('ingestFileAttachmentForProject: attachment is not document')","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/janhq/jan/blob/7205d770c1e097c3daf35a911176410e93bc5564/web-app/src/services/uploads/default.ts#L1-L34","documentation":"ingestFileAttachment only processes attachments whose type is exactly 'document'; it throws this error otherwise. This is the document-ingestion counterpart to ingestImage, feeding the RAG extension's ingestAttachments API.","triggerScenarios":"Calling uploadsService.ingestFileAttachment(threadId, attachment) with an attachment whose type is 'image' or any value other than 'document'.","commonSituations":"A fallback path sends image attachments to the document ingestion API; attachment type defaults were not populated when the attachment was created; the UI allows dropping images into a document upload zone.","solutions":["Verify attachment.type === 'document' before calling ingestFileAttachment; route images to ingestImage","Correct the attachment construction so documents receive type 'document'","If accepting mixed uploads, dispatch on attachment.type at the call site"],"exampleFix":"// before\nawait uploads.ingestFileAttachment(threadId, att) // att.type may be 'image'\n// after\nif (att.type !== 'document') throw new Error('Only document attachments are supported here')\nawait uploads.ingestFileAttachment(threadId, att)","handlingStrategy":"validation","validationCode":"if (attachment.type !== 'document') throw new Error(`Expected document attachment, got: ${attachment.type}`)","typeGuard":"const isDocumentAttachment = (a: Attachment): a is Attachment & { type: 'document' } => a.type === 'document'","tryCatchPattern":"try {\n  await uploads.ingestFileAttachment(threadId, att)\n} catch (e) {\n  if (e instanceof Error && e.message.includes('attachment is not document')) {\n    notifyUser(`${att.name} is not a supported document`)\n    return\n  }\n  throw e\n}","preventionTips":["Route attachments by type at a single dispatcher instead of calling ingest methods ad hoc","Set attachment.type deterministically from the file MIME type during selection","Write a unit test asserting each ingest method's accepted type"],"tags":["type-guard","uploads","invalid-argument"],"backgroundTag":"invalid-argument-value","analyzedSha":"7205d770c1e097c3daf35a911176410e93bc5564","analyzedAt":"2026-09-17T14:27:30.100Z","contentChangedAt":"2026-09-17T14:27:30.100Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}