janhq/jan · error

ingestFileAttachment: attachment is not document

Error message

ingestFileAttachment: attachment is not document

What it means

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.

Solutions

  1. Verify attachment.type === 'document' before calling ingestFileAttachment; route images to ingestImage
  2. Correct the attachment construction so documents receive type 'document'
  3. If accepting mixed uploads, dispatch on attachment.type at the call site

Example fix

// before
await uploads.ingestFileAttachment(threadId, att) // att.type may be 'image'
// after
if (att.type !== 'document') throw new Error('Only document attachments are supported here')
await uploads.ingestFileAttachment(threadId, att)
Defensive patterns

Strategy: validation

Validate before calling

if (attachment.type !== 'document') throw new Error(`Expected document attachment, got: ${attachment.type}`)

Type guard

const isDocumentAttachment = (a: Attachment): a is Attachment & { type: 'document' } => a.type === 'document'

Try / catch

try {
  await uploads.ingestFileAttachment(threadId, att)
} catch (e) {
  if (e instanceof Error && e.message.includes('attachment is not document')) {
    notifyUser(`${att.name} is not a supported document`)
    return
  }
  throw e
}

Prevention

When it happens

Trigger: Calling uploadsService.ingestFileAttachment(threadId, attachment) with an attachment whose type is 'image' or any value other than 'document'.

Common situations: 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.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of janhq/jan@7205d770c1 (2026-09-17). Data as JSON: /api/errors/257ff583f7dac1b1. Report an issue: GitHub.

Appendix: source

Thrown at web-app/src/services/uploads/default.ts:16

import type { UploadsService, UploadResult } from './types'
import type { Attachment } from '@/types/attachment'
import { ulid } from 'ulidx'
import { ExtensionManager } from '@/lib/extension'
import { ExtensionTypeEnum, type RAGExtension, type IngestAttachmentsResult } from '@janhq/core'

export class DefaultUploadsService implements UploadsService {
  async ingestImage(_threadId: string, attachment: Attachment): Promise<UploadResult> {
    if (attachment.type !== 'image') throw new Error('ingestImage: attachment is not image')
    // Placeholder upload flow; swap for real API call when backend is ready
    await new Promise((r) => setTimeout(r, 100))
    return { id: ulid() }
  }

  async ingestFileAttachment(threadId: string, attachment: Attachment): Promise<UploadResult> {
    if (attachment.type !== 'document') throw new Error('ingestFileAttachment: attachment is not document')
    const ext = ExtensionManager.getInstance().get<RAGExtension>(ExtensionTypeEnum.RAG)
    if (!ext?.ingestAttachments) throw new Error('RAG extension not available')
    const res: IngestAttachmentsResult = await ext.ingestAttachments(threadId, [
      { path: attachment.path!, name: attachment.name, type: attachment.fileType, size: attachment.size },
    ])
    const files = res.files
    if (Array.isArray(files) && files[0]?.id) {
      return {
        id: files[0].id,
        size: typeof files[0].size === 'number' ? Number(files[0].size) : undefined,
        chunkCount: typeof files[0].chunk_count === 'number' ? Number(files[0].chunk_count) : undefined,
      }
    }
    throw new Error('Failed to resolve ingested attachment id')
  }

  async ingestFileAttachmentForProject(projectId: string, attachment: Attachment): Promise<UploadResult> {
    if (attachment.type !== 'document') throw new Error('ingestFileAttachmentForProject: attachment is not document')

View on GitHub (pinned to 7205d770c1)