CherryHQ/cherry-studio · error · Error

Document conversion produced no text

Error message

Document conversion produced no text

What it means

Generic Error thrown by CherryDocumentTools.call when the anydoc document-to-Markdown converter returns an empty or whitespace-only string after trimming. The input file was read and decoded, but the converter extracted no text content. This usually means the source document is a scanned PDF without OCR, an image-only file, an empty document, or an unsupported/corrupt format that silently yields no output.

Source

Thrown at src/main/ai/mcp/servers/cherryDocumentTools.ts:136

        inputSchema: toMcpInputSchema(toMarkdownInputSchema)
      }
    ]
  }

  handles(toolName: string): boolean {
    return toolName === TO_MARKDOWN_TOOL_NAME
  }

  async call(args: unknown, signal: AbortSignal): Promise<CallToolResult> {
    try {
      const { path: sourcePath } = toMarkdownInputSchema.parse(args)
      const source = await resolveDocumentSource(this.context, sourcePath)
      throwIfAborted(signal)

      const anydoc = await loadAnydocModule()
      const format = anydoc.formatFromExtension(path.extname(source.filename)) ?? undefined
      const markdown = (await anydoc.toMarkdownBytes(Buffer.from(source.data, 'base64'), format)).trim()
      if (!markdown) throw new Error('Document conversion produced no text')
      throwIfAborted(signal)

      const outputDirectory = path.join(this.context.agentDataPath, 'tmp', 'to-markdown')
      await mkdir(outputDirectory, { recursive: true })
      await cleanupStaleOutputs(outputDirectory).catch((error) => {
        logger.warn('Failed to clean stale document conversion outputs', error as Error)
      })

      const outputPath = path.join(outputDirectory, `${randomUUID()}.md`)
      await writeFile(outputPath, markdown, { encoding: 'utf-8', flag: 'wx' })
      const output = toMarkdownOutputSchema.parse({ path: outputPath, chars: markdown.length })
      return { content: [{ type: 'text', text: JSON.stringify(output) }] }
    } catch (error) {
      if (signal.aborted || isAbortError(error)) throw error
      const normalizedError = error instanceof Error ? error : new Error(String(error))
      logger.error('cherry-tools document conversion failed', normalizedError)
      return errorResult(normalizedError)
    }

View on GitHub (pinned to 726446b54c)

Solutions

  1. Verify the source file actually contains extractable text (open it in a viewer).
  2. For scanned PDFs, run OCR first, then pass the OCR'd file to to_markdown.
  3. Confirm the file is not empty or password-protected.
  4. Check that the file extension matches the real format and that anydoc supports it.

Example fix

// before
const markdown = (await anydoc.toMarkdownBytes(Buffer.from(source.data, 'base64'), format)).trim()
if (!markdown) throw new Error('Document conversion produced no text')

// after
const markdown = (await anydoc.toMarkdownBytes(Buffer.from(source.data, 'base64'), format)).trim()
if (!markdown) {
  return errorResult(new Error('No text could be extracted. If this is a scanned document, run OCR first.'))
}
Defensive patterns

Strategy: validation

Validate before calling

// Pre-check: ensure the file has extractable content before calling to_markdown
const buf = Buffer.from(source.data, 'base64')
if (buf.length === 0) {
  throw new Error('Source file is empty')
}
// For PDFs, check page count or text layer before conversion if possible

Try / catch

try {
  const result = await documentTools.call(args, signal)
  if (result.isError) {
    // check if the error message indicates empty conversion
    const text = result.content[0]?.text ?? ''
    if (text.includes('produced no text')) {
      // suggest OCR for scanned documents
    }
  }
  return result
} catch (e) {
  if (e instanceof Error && e.message.includes('produced no text')) {
    // run OCR then retry, or inform the user
  }
  throw e
}

Prevention

When it happens

Trigger: Calling the to_markdown tool on: an image-only or scanned PDF without a text layer; an empty or near-empty file; a password-protected PDF; a format anydoc cannot parse; a corrupt/truncated file.

Common situations: User uploads a scanned document expecting text extraction but OCR is not enabled; the file extension does not match its actual content; the file was truncated during upload/transfer; the format is unsupported by the anydoc library version installed.

Related errors


AI-assisted analysis of CherryHQ/cherry-studio@726446b54c (2026-08-12). Data as JSON: /api/errors/907abc24b586efb6. Report an issue: GitHub.