{"record":{"id":"8cfd9d16c7174e74","repo":"janhq/jan","slug":"ingestimage-attachment-is-not-image","errorCode":null,"errorMessage":"ingestImage: attachment is not image","messagePattern":"ingestImage: attachment is not image","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"web-app/src/services/uploads/default.ts","lineNumber":9,"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,","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/janhq/jan/blob/fad3f12a147d138388a66f0d92a02b2675f65294/web-app/src/services/uploads/default.ts#L1-L27","documentation":"Thrown by DefaultUploadsService.ingestImage when attachment.type !== 'image'. It is a contract guard - this method only handles image attachments; routing anything else here is a caller bug, not a runtime/environment condition.","triggerScenarios":"ingestImage(threadId, attachment) is called with an attachment whose type field is not 'image' (e.g., a document, PDF, or unknown type routed into the image path).","commonSituations":"Incorrect dispatch in the upload pipeline; an attachment misclassified before reaching the service; attachment type values changed during a refactor.","solutions":["Ensure the caller routes only image attachments to ingestImage.","Dispatch by attachment.type from a single location."],"exampleFix":"// before: every attachment routed to ingestImage\nawait uploads.ingestImage(threadId, att)\n// after: dispatch by type\nif (att.type === 'image') await uploads.ingestImage(threadId, att)\nelse if (att.type === 'document') await uploads.ingestFileAttachment(threadId, att)","handlingStrategy":"validation","validationCode":"if (attachment.type !== 'image') throw new Error('Skip non-image')","typeGuard":"function isImageAttachment(a: Attachment): boolean { return a.type === 'image' }","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"}