rtk-ai/rtk · error

listing shorter than file2

Error message

listing shorter than file2

What it means

Test-helper panic in a rewrite-fixing harness: for each line of file2 not removed, the code takes a fixed slot or pulls the next line from the original listing; `.expect("listing shorter than file2")` panics when the listing (e.g. cargo fix/npm audit fix suggestions) has fewer entries than the surviving lines of file2, and the following assert panics when it has more. It enforces a 1:1 correspondence between the rewritten file and the fix listing.

Solutions

  1. Regenerate the test fixtures so the fix listing length matches the non-removed line count of file2.
  2. Check the `removed` mask computation — an over- or under-count of removed lines desynchronizes the pairing.
  3. If the real tool legitimately skips lines, change the helper to pad with `None` instead of panicking.

Example fix

// before
slot.or_else(|| stream.next())
    .expect("listing shorter than file2")
// after
slot.or_else(|| stream.next()).unwrap_or_else(|| {
    panic!("listing shorter than file2: needed a line for slot {i}")
})
Defensive patterns

Strategy: validation

Validate before calling

// before pairing, assert counts agree
let kept: Vec<_> = file2_lines.iter().enumerate().filter(|(i, _)| !removed[*i]).collect();
assert_eq!(kept.len(), stream.len(), "listing/file2 length mismatch");

Try / catch

slot.or_else(|| stream.next())
    .unwrap_or_else(|| panic!("listing shorter than file2 at slot {i}"));

Prevention

When it happens

Trigger: Calling this helper with a `stream` (fix suggestion listing) whose line count differs from the count of non-removed lines in file2 — typically when the fixer outputs fewer or extra suggestions, or when removed-line filtering is miscounted.

Common situations: Tool output format changes (a fixer skips suggestions for some lines or emits combined suggestions), fixtures regenerated with a different tool version, or an off-by-one in the `removed` mask.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of rtk-ai/rtk@0924356b4c (2026-09-19). Data as JSON: /api/errors/443308c721f5956b. Report an issue: GitHub.

Appendix: source

Thrown at src/cmds/git/diff_cmd.rs:7326

                            assert_eq!(a[l1 - 1], old, "~ names file1 at {l1}");
                            rewritten[l1 - 1] = Some(new.to_string());
                        }
                    }
                }
                other => panic!("unexpected marker {other:?} in {line:?}"),
            }
        }

        let mut stream = a
            .iter()
            .enumerate()
            .filter(|(i, _)| !removed[*i])
            .map(|(i, l)| rewritten[i].clone().unwrap_or_else(|| (*l).to_string()));
        let out: Vec<String> = fixed
            .into_iter()
            .map(|slot| {
                slot.or_else(|| stream.next())
                    .expect("listing shorter than file2")
            })
            .collect();
        assert!(stream.next().is_none(), "listing longer than file2");
        out
    }

    #[test]
    fn test_condensed_listing_reconstructs_the_second_file() {
        // The pairing is by similarity and may cross; the render has to carry
        // enough numbers that a reader rebuilding file2 gets file2. A
        // small alphabet of similar lines makes crossings frequent, which a
        // realistic corpus does not.
        let mut seed = 0xc0ff_ee00_u64;
        let mut crossed = 0usize;
        for _ in 0..3_000 {
            let n = (lcg(&mut seed) % 12) as usize;
            let m = (lcg(&mut seed) % 12) as usize;
            let mut make_lines = |k: usize| -> Vec<String> {

View on GitHub (pinned to 0924356b4c)