sinelaw/fresh · warning · LargeFileEncodingConfirmation
( MB) requires full load. (l)oad, (e)ncoding, (C)ancel?
Error message
{} ({:.0} MB) requires full load. (l)oad, (e)ncoding, (C)ancel? What it means
When opening a large file, load_large_file_internal can defer full loading (partial/lazy loading) — but only for encodings that support it. If the chosen encoding requires reading the entire file (requires_full_file_load()) and the call wasn't forced, the loader bails out with LargeFileEncodingConfirmation so the UI can ask the user to confirm a full load, pick another encoding, or cancel.
Solutions
- Handle the LargeFileEncodingConfirmation error in your caller: surface the (l)oad/(e)ncoding/(C)ancel choice to the user and retry accordingly.
- Retry the load with force_full_load=true to proceed with a full read (mind memory usage for very large files).
- Retry with a different encoding that does not require full-file loading (e.g. a resynchronizable/UTF-8-compatible one) to keep lazy loading.
- Cancel if full load is unacceptable; the file is not loaded and no data is modified.
Example fix
// before
buffer.load_large_file(path, file_size, encoding, /*force_full_load*/ false)?;
// after: confirm or force based on user decision
match buffer.load_large_file(path, file_size, encoding, false) {
Err(e) if e.downcast_ref::<LargeFileEncodingConfirmation>().is_some() => {
if user_chose_load {
buffer.load_large_file(path, file_size, encoding, true)?;
}
}
r => r?,
} Defensive patterns
Strategy: validation
Validate before calling
// before loading a large file, check whether the encoding forces a full read
let needs_full = file_size > LARGE_FILE_THRESHOLD
&& !is_binary
&& encoding.requires_full_file_load(); Try / catch
match buffer.load_large_file(path, size, enc, false) {
Err(e) if e.downcast_ref::<LargeFileEncodingConfirmation>().is_some() => {
// show (l)oad / (e)ncoding / (C)ancel prompt, then retry or abort
}
other => other?,
} Prevention
- Check encoding.requires_full_file_load() before choosing lazy loading for big files.
- Prefer resynchronizable/UTF-8-compatible encodings for large-file workflows.
- Never pass force_full_load=true blindly on multi-GB files; confirm memory headroom first.
When it happens
Trigger: Loading a file that exceeds the large-file threshold with a non-binary encoding whose requires_full_file_load() returns true (e.g. encodings needing full-file conversion like UTF-16 with detection, or non-resynchronizable encodings), without setting force_full_load=true on the load call.
Common situations: Opening a multi-GB UTF-16 or non-UTF-8 encoded log/data file; users hitting the interactive prompt '(l)oad, (e)ncoding, (C)ancel?' and either choosing an option; scripts or tests calling the loader programmatically without force_full_load and being surprised by the bail.
Related errors
AI-assisted analysis of sinelaw/fresh@67894ca546 (2026-09-13).
Data as JSON: /api/errors/bee83576a7f4f68c.
Report an issue: GitHub.
Appendix: source
Thrown at crates/fresh-editor-core/src/model/buffer/mod.rs:643
format::detect_encoding_or_binary(&sample, file_size > sample_size);
let is_binary = detected_binary && !force_text;
// Binary files skip encoding conversion to preserve raw bytes — and,
// like large text, are never slurped: reading a 2 GB zip whole cost
// ~1.2x its size resident and froze the editor thread for the read plus
// the line scan (issue #3142). A binary buffer opens read-only, so the
// lazy piece below serves it just as well.
//
// The `requires_full_load` gates below stop a non-resynchronizable
// *text* encoding being decoded chunk-wise; binary is never decoded, so
// they do not apply to it — as before, when it returned above them.
if !is_binary {
// Check if encoding requires full file loading
let requires_full_load = encoding.requires_full_file_load();
// For non-resynchronizable encodings, require confirmation unless forced
if requires_full_load && !force_full_load {
anyhow::bail!(LargeFileEncodingConfirmation {
path: path.to_path_buf(),
file_size,
encoding,
});
}
}
// For encodings that require full load (non-resynchronizable or non-UTF-8),
// load the entire file and convert
if !is_binary && !matches!(encoding, Encoding::Utf8 | Encoding::Ascii) {
tracing::info!(
"Large file with non-UTF-8 encoding ({:?}), loading fully for conversion",
encoding
);
let contents = fs.read_file(path)?;
let mut buffer = Self::from_bytes_normalizing(contents, fs, normalize_cr);
buffer.persistence.set_file_path(path.to_path_buf());
buffer.persistence.clear_modified();View on GitHub (pinned to 67894ca546)