OtterMind/Chat2DB · error · BusinessException
ai.attachment.emptyContent
ai.attachment.emptyContent
Error message
ai.attachment.emptyContent
What it means
Thrown by AiAttachmentServiceImpl.parse(String, InputStream) when the parsed content, after normalizeText(), is blank. The file was readable and the type was supported, but no extractable text remained. The i18n message resolves to 'File content is empty or cannot be parsed'.
Source
Thrown at chat2db-community-server/chat2db-community-domain/chat2db-community-domain-core/src/main/java/ai/chat2db/community/domain/core/impl/ai/AiAttachmentServiceImpl.java:155
}
private ChatAttachment parse(String fileName, InputStream inputStream) throws IOException {
String extension = StringUtils.lowerCase(FilenameUtils.getExtension(fileName));
validateExtension(extension);
String content = switch (extension) {
case "pdf" -> parsePdf(inputStream);
case "docx" -> parseDocx(inputStream);
case "doc" -> parseDoc(inputStream);
case "csv" -> parseCsv(inputStream);
case "xls", "xlsx" -> parseWorkbook(inputStream);
case "md", "txt", "json" -> readPlainText(inputStream);
default -> throw new BusinessException("ai.attachment.unsupportedFileType");
};
String normalizedContent = normalizeText(content);
if (StringUtils.isBlank(normalizedContent)) {
throw new BusinessException("ai.attachment.emptyContent");
}
boolean truncated = normalizedContent.length() > MAX_CONTENT_LENGTH;
String finalContent = truncated ? normalizedContent.substring(0, MAX_CONTENT_LENGTH) : normalizedContent;
ChatAttachment attachment = new ChatAttachment();
attachment.setFileName(fileName);
attachment.setFileType(extension);
attachment.setContentCategory(resolveContentCategory(extension));
attachment.setContent(finalContent);
attachment.setContentLength(normalizedContent.length());
attachment.setTruncated(truncated);
return attachment;
}
private void validateExtension(String extension) {
if (StringUtils.isBlank(extension) || !SUPPORTED_EXTENSIONS.contains(extension)) {
throw new BusinessException("ai.attachment.unsupportedFileExtensions");View on GitHub (pinned to 5ee1e990e7)
Solutions
- Inform the user the file yielded no extractable text and ask for a text-based version (e.g. OCR the scanned PDF first).
- For spreadsheets, confirm the data is within the first 100 rows / 20 columns the parser reads.
- Pre-validate non-empty content client-side for plain-text types before uploading.
Example fix
// before: uploading a scanned PDF (no text layer)
service.parse(req); // -> emptyContent
// after: run OCR to produce a text PDF, or upload the extracted text as .txt
// client-side pre-check for plain text types
if (isTextType(ext) && file.size === 0) {
notifyUser("file is empty");
return;
} Defensive patterns
Strategy: validation
Validate before calling
// client-side: warn on likely-empty content for text types
if (isPlainText(ext) && file.size === 0) {
notifyUser("file is empty"); return;
} Try / catch
try {
service.parse(param);
} catch (BusinessException e) {
if ("ai.attachment.emptyContent".equals(e.getCode())) {
return ResponseEntity.unprocessableEntity()
.body("no extractable text; for scanned PDFs run OCR first");
}
throw e;
} Prevention
- For scanned PDFs, OCR before upload to create a text layer.
- For spreadsheets, keep data within the first 100 rows / 20 columns.
- Pre-validate non-empty content for plain-text types before uploading.
When it happens
Trigger: A supported file parses successfully but yields no text: a scanned/image-only PDF with no OCR text layer; an empty .txt/.md/.json/.csv; a docx/xlsx whose visible cells/paragraphs are all whitespace; a workbook where only header rows exceed the row/column caps leaving no body text.
Common situations: Users uploading scanned PDFs expecting text extraction; uploading a template docx that is visually empty; uploading a spreadsheet whose data lives beyond MAX_SHEET_ROWS(100)/MAX_SHEET_COLUMNS(20) so the bounded reader returns nothing; a csv with only a header and no rows.
Related errors
- ai.attachment.localParseFailed
- ai.attachment.unsupportedFileType
- ai.attachment.filePathRequired
- ai.attachment.fileNotFound
- ai.attachment.unsupportedFileExtensions
AI-assisted analysis of OtterMind/Chat2DB@5ee1e990e7 (2026-08-14).
Data as JSON: /api/errors/36643bcc17d5da1e.
Report an issue: GitHub.