Hmbown/CodeWhale · error · io::Error

LSP file exceeds the document limit

Error message

LSP file exceeds the document limit

What it means

read_workspace_text reads at most MAX_DOCUMENT_BYTES+1 bytes and rejects any workspace document larger than MAX_DOCUMENT_BYTES with InvalidData. The cap bounds memory used when serving file contents to LSP features.

Solutions

  1. Exclude the oversized file from LSP analysis (ignore patterns / don't request diagnostics for it).
  2. Split or shrink the file; for generated artifacts, regenerate them smaller or gitignore them and skip analysis.
  3. If the file is legitimately needed, pre-process it (e.g. pretty-print a minified bundle only partially, or index it instead).
Defensive patterns

Strategy: validation

Validate before calling

let size = std::fs::metadata(path)?.len();
if size > MAX_DOCUMENT_BYTES { eprintln!("skip LSP for oversized file {path:?}"); }

Try / catch

match read_workspace_text(p) {
    Err(e) if e.kind() == std::io::ErrorKind::InvalidData => eprintln!("document too large; skipped {p:?}"),
    other => other.map(|_| ()),
}

Prevention

When it happens

Trigger: Any read_workspace_text call (or its callers diagnostics_for/diagnostics_for_custom/intelligence_at_revision/semantic_locations/diagnostics_for_paths) where the workspace file's byte size exceeds MAX_DOCUMENT_BYTES.

Common situations: Opening generated files, lockfiles, minified bundles, large JSON datasets, or vendored blobs that the LSP is asked to diagnose or analyze.

Understand the failure class

Background: "File too large" / "file size exceeds limit" errors: why libraries cap file sizes and how to fix them — this error's family across 46 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/791e9e9af9359b37. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/lsp/mod.rs:242

            let relative = requested
                .strip_prefix(&root)
                .or_else(|_| requested.strip_prefix(&canonical_root))
                .map_err(|_| {
                    std::io::Error::new(
                        std::io::ErrorKind::PermissionDenied,
                        "LSP file is outside the workspace",
                    )
                })?;
            // Match the existing workspace file serving ceiling. Decode only
            // bounded UTF-8 bytes from the same no-follow workspace opener.
            const MAX_DOCUMENT_BYTES: u64 = 16 * 1024 * 1024;
            let file = crate::fleet::files::WorkspaceFile::open(&canonical_root, relative, false)?;
            let mut bytes = Vec::new();
            file.open_file()?
                .take(MAX_DOCUMENT_BYTES + 1)
                .read_to_end(&mut bytes)?;
            if bytes.len() as u64 > MAX_DOCUMENT_BYTES {
                return Err(std::io::Error::new(
                    std::io::ErrorKind::InvalidData,
                    "LSP file exceeds the document limit",
                ));
            }
            String::from_utf8(bytes)
                .map_err(|error| std::io::Error::new(std::io::ErrorKind::InvalidData, error))
        })
        .await
        .map_err(std::io::Error::other)?
    }

    /// Inject a fake transport for a language. Used by tests so we never
    /// fork a real LSP server in CI.
    #[cfg(test)]
    pub async fn install_test_transport(&self, lang: Language, transport: Arc<dyn LspTransport>) {
        self.test_transports.lock().await.insert(lang, transport);
    }

View on GitHub (pinned to 73e0f67d83)