tursodatabase/turso · error · std::io::Error

UnexpectedEof

UnexpectedEof

Error message

range exceeds file length

What it means

The in-memory FileHandle used by the FTS token collector serves read_bytes(range) from a byte buffer; a range whose end exceeds the buffer length returns UnexpectedEof "range exceeds file length". It guards against offset metadata claiming data that was never written.

Source

Thrown at core/index_method/fts.rs:854

impl std::fmt::Debug for InMemoryFileHandle {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("InMemoryFileHandle")
            .field("len", &self.data.len())
            .finish()
    }
}

impl HasLen for InMemoryFileHandle {
    fn len(&self) -> usize {
        self.data.len()
    }
}

impl FileHandle for InMemoryFileHandle {
    fn read_bytes(&self, range: Range<usize>) -> std::io::Result<OwnedBytes> {
        if range.end > self.data.len() {
            return Err(std::io::Error::new(
                std::io::ErrorKind::UnexpectedEof,
                "range exceeds file length",
            ));
        }
        if range.start >= range.end {
            return Ok(OwnedBytes::empty());
        }
        Ok(OwnedBytes::new(Arc::clone(&self.data)).slice(range))
    }
}

/// In-memory writer for HybridBTreeDirectory.
struct HybridWriter {
    path: PathBuf,
    buffer: Vec<u8>,
    directory: HybridBTreeDirectory,
}

View on GitHub (pinned to 0e69fa4af1)

Solutions

  1. Rebuild the FTS index so metadata and data are regenerated consistently
  2. If it recurs on rebuild, capture the query and index DDL and report it as a turso bug
  3. Restore from backup for production data
Defensive patterns

Strategy: fallback

Try / catch

match handle.read_bytes(range.clone()) {
    Err(ref e) if e.kind() == std::io::ErrorKind::UnexpectedEof => rebuild_index(),
    r => r,
}

Prevention

When it happens

Trigger: Index offset/size metadata inconsistent with the in-memory data - a truncated write buffer after an interrupt, a collector reused after its data was replaced, or a computed read range beyond what was flushed.

Common situations: Crash or interrupt during an index build leaving short data, or an FTS index produced by a mismatched turso version.

Related errors


AI-assisted analysis of tursodatabase/turso@0e69fa4af1 (2026-08-20). Data as JSON: /api/errors/e9c8b630b677620a. Report an issue: GitHub.