janhq/jan · error

ingestFileAttachmentForProject: attachment is not document

Error message

ingestFileAttachmentForProject: attachment is not document

What it means

ingestFileAttachmentForProject, the project-scoped variant of document ingestion, only accepts attachments whose type is exactly 'document' and throws this error for any other type. It is the same style of upfront guard as in ingestFileAttachment.

Solutions

  1. Guard with attachment.type === 'document' before invoking ingestFileAttachmentForProject and route other types elsewhere
  2. Fix attachment construction so document files are labeled type 'document'
  3. Dispatch on attachment.type at the call site when handling mixed uploads

Example fix

// before
await uploads.ingestFileAttachmentForProject(projectId, att)
// after
if (att.type === 'document') {
  await uploads.ingestFileAttachmentForProject(projectId, att)
}
Defensive patterns

Strategy: type-guard

Validate before calling

if (attachment.type !== 'document') { console.warn('Project upload skipped non-document', attachment.name); return }

Type guard

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

Try / catch

try {
  await uploads.ingestFileAttachmentForProject(projectId, att)
} catch (e) {
  if (e instanceof Error && e.message.includes('attachment is not document')) {
    notifyUser(`${att.name} cannot be added to a project: not a document`)
    return
  }
  throw e
}

Prevention

When it happens

Trigger: Calling uploadsService.ingestFileAttachmentForProject(projectId, attachment) with an attachment whose type is not 'document' (e.g. 'image').

Common situations: A project upload flow reuses one handler for all dropped files; attachment.type was left unset or misclassified when building the Attachment object.

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/3375ceca98ac8282. Report an issue: GitHub.

Appendix: source

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

    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')
    const ext = ExtensionManager.getInstance().get<RAGExtension>(ExtensionTypeEnum.RAG)
    if (!ext?.ingestAttachmentsForProject) throw new Error('RAG extension does not support project-level ingestion')
    const res: IngestAttachmentsResult = await ext.ingestAttachmentsForProject(projectId, [
      { 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')
  }
}

View on GitHub (pinned to 7205d770c1)