{"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":"Error","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/fad3f12a147d138388a66f0d92a02b2675f65294/web-app/src/services/uploads/default.ts#L1-L34","documentation":"Thrown by DefaultUploadsService.ingestFileAttachment when attachment.type !== 'document'. It is a contract guard - this method only handles document attachments; passing anything else is a caller bug.","triggerScenarios":"ingestFileAttachment(threadId, attachment) is called with an attachment whose type field is not 'document' (e.g., an image or unknown type routed into the document path).","commonSituations":"Incorrect dispatch in the upload pipeline; an image attachment reaching the document path; attachment type values changed during a refactor.","solutions":["Route only document attachments to ingestFileAttachment.","Dispatch by attachment.type from a single location."],"exampleFix":"// before: document path receives all attachments\nawait uploads.ingestFileAttachment(threadId, att)\n// after: dispatch by type\nif (att.type === 'document') await uploads.ingestFileAttachment(threadId, att)\nelse if (att.type === 'image') await uploads.ingestImage(threadId, att)","handlingStrategy":"validation","validationCode":"if (attachment.type !== 'document') throw new Error('Skip non-document')","typeGuard":"function isDocumentAttachment(a: Attachment): boolean { return a.type === 'document' }","tryCatchPattern":null,"preventionTips":["Centralize type-based dispatch in one place.","Use a discriminated union for Attachment to get compile-time safety on type."],"tags":["validation","attachment","type-mismatch","uploads","programming-bug"],"backgroundTag":null,"analyzedSha":"fad3f12a147d138388a66f0d92a02b2675f65294","analyzedAt":"2026-08-12T20:33:47.516Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}