AlexsJones/llmfit · error

files list is not empty

Error message

files list is not empty

What it means

Panic from sorted.first().expect("files list is not empty") in the GGUF auto-select fallback (main.rs:1664-1676). The flow earlier fetches repo files via LlamaCppProvider::list_repo_gguf_files and exits with a friendly error at main.rs:1603-1607 when files.is_empty(), so by the time this branch runs (no quantization fits the memory budget, pick the smallest) the Vec is provably non-empty. The expect documents that established invariant; in the current code it is unreachable, and firing it means the upstream guard was removed, reordered, or the selection started operating on a different collection.

Source

Thrown at llmfit-tui/src/main.rs:1668

            let specs = detect_specs(overrides);
            specs
                .total_gpu_vram_gb
                .or(Some(specs.available_ram_gb))
                .unwrap_or(16.0)
        };
        if let Some(result) = LlamaCppProvider::select_best_gguf(&files, mem_budget) {
            println!(
                "Selected {} ({:.1} GB) for {:.0} GB memory budget",
                result.0,
                result.1 as f64 / 1_073_741_824.0,
                mem_budget
            );
            result
        } else {
            // Nothing fits — pick smallest
            let mut sorted = files.clone();
            sorted.sort_by_key(|(_, s)| *s);
            let (f, s) = sorted.first().expect("files list is not empty");
            println!(
                "Warning: No quantization fits within {:.0} GB. Downloading smallest: {} ({:.1} GB)",
                mem_budget,
                f,
                *s as f64 / 1_073_741_824.0
            );
            (f.clone(), *s)
        }
    };

    // If the selected file is one shard of a multi-part model, expand it
    // here so we can show the user the full size and part count up front.
    // The actual download is still driven by `download_gguf`, which performs
    // the same expansion internally.
    let shard_set = llmfit_core::providers::collect_shard_set(&files, &filename);
    let (display_name, display_size) = if let Some(ref shards) = shard_set {
        let total: u64 = shards.iter().map(|(_, s)| *s).sum();
        let first = shards[0].0.clone();

View on GitHub (pinned to acc7e40c3a)

Solutions

  1. If you hit this panic in a dev build, check git diff for changes to the files.is_empty() guard at llmfit-tui/src/main.rs:1603 — restoring it (exit with the 'No GGUF files found' message) is the fix.
  2. Keep the guard in the same function as the selection so extraction into a helper cannot drop it, or convert the expect into an explicit empty-handling branch.
  3. Verify list_repo_gguf_files still fails loud (not silently-empty) on network/API errors.
  4. For end users seeing this in a released binary: report it as a bug — the invariant held at release time.

Example fix

// before
let mut sorted = files.clone();
sorted.sort_by_key(|(_, s)| *s);
let (f, s) = sorted.first().expect("files list is not empty");

// after — make the guard local instead of relying on a distant check
let mut sorted = files.clone();
sorted.sort_by_key(|(_, s)| *s);
let Some((f, s)) = sorted.first() else {
    eprintln!("No GGUF files found in repository '{repo_id}'.");
    std::process::exit(1);
};
Defensive patterns

Strategy: validation

Validate before calling

// Guard the collection before entering any auto-select/first() logic.
if files.is_empty() {
    eprintln!("No GGUF files found in repository '{repo_id}'.");
    eprintln!("Make sure this is a valid GGUF repository on HuggingFace.");
    std::process::exit(1);
}
let (filename, file_size) = select_or_smallest(&files, mem_budget);

Prevention

When it happens

Trigger: Only reachable in `llmfit download <repo>` (auto-select path, no --quant) if the empty-check at main.rs:1603 is deleted or moved after selection, or if a refactor passes a different/filtered files Vec into the fallback. A repo whose file list changes between the check and use cannot cause it — the same Vec is cloned and sorted.

Common situations: Contributor refactors of the download command that extract the auto-select logic into a helper without carrying the emptiness guard; code paths where list_repo_gguf_files' error handling changes to return an empty Vec silently on network failure instead of the caller exiting.

Related errors


AI-assisted analysis of AlexsJones/llmfit@acc7e40c3a (2026-08-17). Data as JSON: /api/errors/9bd618a121787798. Report an issue: GitHub.