rtk-ai/rtk · error

noise, not raw

Error message

noise, not raw

What it means

`.expect("noise, not raw")` panic: `condense_unified_diff_strict()` returned None on a synthetic mbox-format-patch string used to test the documented "noise, not loss" bounds. Rule 4 under test: mbox prose that quotes a whole well-formed header-plus-hunk block (`--- a/f\n+++ b/f\n@@ ...`) inside the message fabricates one phantom `[file] f` entry, and the condenser must still parse (return Some) with exactly 2 `[file]` entries (f phantom + real g). None means the parser over-triggered its raw fallback on the quoted block.

Solutions

  1. Ensure the mbox `From ... Mon Sep 17` line always opens a message/prose region so in-prose header-shaped lines stay noise.
  2. Verify the `---` + diffstat after the message is consumed as the stat separator, re-enabling patch mode for the real `diff --git` section.
  3. Check the raw-fallback trigger only fires for unread column-0 lines after patch context begins, not inside the message region.
  4. Update the fixture/string if the rule set changed and this scenario is no longer in-bounds.

Example fix

// before
if looks_like_header(line) && !in_patch { return None; } // prose header kills stream
// after
if looks_like_header(line) && !in_patch && !in_message_region { return None; }
Defensive patterns

Strategy: validation

Validate before calling

let out = condense_unified_diff_strict(&mbox_with_quoted_diff);
assert!(out.as_deref().map_or(false, |o| o.matches("[file] ").count() == 2), "expected phantom + real entry");

Type guard

fn condense_checked(diff: &str) -> Option<String> { crate::cmds::git::diff_cmd::condense_unified_diff_strict(diff) }

Try / catch

let out = condense_unified_diff_strict(input)
    .unwrap_or_else(|| input.to_string()); // 'noise, not loss': raw fallback is always safe

Prevention

When it happens

Trigger: Calling `condense_unified_diff_strict()` on the inline `phantom` string (mbox `From ...` header, prose containing a fake `--- a/f / +++ b/f / @@ -1 +1 @@` block, then `---` diffstat and a real `diff --git a/g b/g` patch) returns None instead of Some with exactly 2 file entries.

Common situations: Pasting formatted patches (`git format-patch` mbox output) containing quoted example diffs into rtk; tightening raw-fallback heuristics until even documented-phantom cases stop parsing; changes to the mbox `From`/`--` boundary handling.

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/18bfc64ebd43c5db. Report an issue: GitHub.

Appendix: source

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

        );
        // A git binary section followed by another producer's header pair
        // (two streams concatenated): the pair opens its own section
        // rather than renaming the binary one and stealing its note.
        let concat = "diff --git a/x.bin b/x.bin\nindex 1111111..2222222 100644\nBinary files a/x.bin and b/x.bin differ\n--- g1/m.txt\t2026-01-01 00:00:00.000000000 +0000\n+++ g2/m.txt\t2026-01-01 00:00:00.000000000 +0000\n@@ -1 +1 @@\n-x\n+y\n";
        assert_eq!(
            condense_unified_diff_strict(concat).as_deref(),
            Some("[file] x.bin (binary)\n[file] g2/m.txt (+1 -1)\n-x\n+y")
        );
        assert_eq!(unquote_shell("$'caf\\351.txt'"), "$'caf\\351.txt'");
    }

    #[test]
    fn documented_bounds_hold() {
        // The doc comment's "noise, not loss" bounds, executable.
        // Rule 4: mbox prose quoting a whole well-formed header-plus-hunk
        // block fabricates a phantom entry.
        let phantom = "From 0e7632a01b00c70cbc9dafcf1f23c71fa6b10de1 Mon Sep 17 00:00:00 2001\nSubject: [PATCH] x\n\nThe old change was:\n--- a/f\n+++ b/f\n@@ -1 +1 @@\n-x\n+y\n---\n g | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/g b/g\n--- a/g\n+++ b/g\n@@ -1 +1 @@\n-p\n+q\n-- \n2.54.0\n";
        let out = condense_unified_diff_strict(phantom).expect("noise, not raw");
        assert_eq!(out.matches("[file] ").count(), 2, "got:\n{out}");
        // Rule 7: a stale `--` in a malformed mbox stream is swallowed.
        let stale = "From 0e7632a01b00c70cbc9dafcf1f23c71fa6b10de1 Mon Sep 17 00:00:00 2001\nSubject: [PATCH] x\n\n---\n g | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/g b/g\n--- a/g\n+++ b/g\n@@ -1 +1 @@\n-p\n+q\n--\n-- \n2.54.0\n";
        assert!(condense_unified_diff_strict(stale).is_some());
        // Rule 8: prose imitating a diffstat line ends the exemption early,
        // but format-patch's own `---` + diffstat right after is read as
        // the stat separator, so the patch still condenses; a marked line
        // between the two is lost content and falls back raw.
        let fake_stat = "From 0e7632a01b00c70cbc9dafcf1f23c71fa6b10de1 Mon Sep 17 00:00:00 2001\nSubject: [PATCH] x\n\n rows | 3\n---\n g | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/g b/g\n--- a/g\n+++ b/g\n@@ -1 +1 @@\n-p\n+q\n-- \n2.54.0\n";
        let out = condense_unified_diff_strict(fake_stat).expect("noise, not raw");
        assert!(out.contains("[file] g (+1 -1)"), "got:\n{out}");
        assert!(
            condense_unified_diff_strict(&fake_stat.replace(" rows | 3\n", " rows | 3\n-lost\n"))
                .is_none()
        );
        // Rule 8: a bodyless `--no-stat` region whose prose wraps a short
        // option to column 0 falls back raw.
        let short = "From aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa Mon Sep 17 00:00:00 2001\nSubject: [PATCH 1/2] one\n\nPass\n-p\nto it.\n-- \n2.54.0\n\nFrom bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb Mon Sep 17 00:00:00 2001\nSubject: [PATCH 2/2] two\n\ndiff --git a/y.txt b/y.txt\n--- a/y.txt\n+++ b/y.txt\n@@ -1 +1 @@\n-p\n+q\n-- \n2.54.0\n";

View on GitHub (pinned to 0924356b4c)