rtk-ai/rtk · error

invalid ctest result prefix regex

Error message

invalid ctest result prefix regex

What it means

This panic message comes from an .expect() on Regex::new for the RESULT_RE static in src/cmds/system/ctest_cmd.rs, which parses ctest 'Test #N: name ... Passed/Failed <time> sec' result lines. rtk compiles its filter regexes once in LazyLock statics; if the pattern were syntactically invalid the program panics at first access instead of returning an error. This is an internal invariant guard — the shipped pattern is valid, so end users should never see it.

Solutions

  1. Check the regex literal near the expect in src/cmds/system/ctest_cmd.rs for syntax errors (balanced groups, valid escapes) and fix it
  2. Verify the regex crate version compiles the pattern: `cargo test ctest` or a quick Regex::new in a test
  3. If you only want output, bypass the filter with `rtk proxy ctest ...` to run ctest unfiltered
  4. Rebuild from a clean tree: `cargo build` and confirm the panic disappears

Example fix

// before
Regex::new(r"(?s)^\s*(?:\d+/(\d+)\s+)?Test\s+#(\d+):\s+(.+?)\s+\.{2,}\s*(?:\*{3})?\s*(.+?)\s+([\d.]+)\s+sec\s*$").expect("invalid ctest result regex")
// after (fix syntax, e.g. missing group close)
Regex::new(r"(?s)^\s*(?:\d+/(\d+)\s+)?Test\s+#(\d+):\s+(.+?)\s+\.{2,}\s*(?:\*{3})?\s*(.+?)\s+([\d.]+)\s+sec\s*$)").expect("invalid ctest result regex")
Defensive patterns

Strategy: validation

Validate before calling

// Rust, at build/dev time
assert!(regex::Regex::new(r"(?s)^\s*(?:\d+/(\d+)\s+)?Test\s+#(\d+):\s+(.+?)\s+\.{2,}\s*(?:\*{3})?\s*(.+?)\s+([\d.]+)\s+sec\s*$").is_ok(), "RESULT_RE must compile");

Prevention

When it happens

Trigger: First access of RESULT_RE during an `rtk ctest` run, if the compiled binary was built from a source edit that broke the regex syntax (e.g. an unbalanced parenthesis or a bad escape like \s misspelled in the raw string).

Common situations: Developers modifying the ctest filter's regex and shipping a typo; tooling or macros mangling the raw string literal; backporting the pattern to an older regex crate whose syntax differs.

Related errors


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

Appendix: source

Thrown at src/cmds/system/ctest_cmd.rs:31

const MAX_SLOWEST: usize = 3;
const MAX_FAILURE_LINES: usize = CAP_WARNINGS;
const MAX_FAILURE_HEAD_LINES: usize = 2;
const MAX_FAILED_LIST_LINES: usize = CAP_LIST;
const MAX_DETECT_PREAMBLE_LINES: usize = 4;
// Failure entries carry a header plus up to `MAX_FAILURE_LINES` detail lines each,
// so this list deviates below `CAP_LIST`; the single-line skipped and raw-trailer
// lists keep the full cap.
const MAX_FAILED_BLOCK_ENTRIES: usize = truncate::reduced(CAP_LIST, 5);

static TEST_RE: LazyLock<Regex> = LazyLock::new(|| {
    Regex::new(
        r"(?s)^\s*(?:\d+/(\d+)\s+)?Test\s+#(\d+):\s+(.+?)\s+\.{2,}\s*(?:\*{3})?\s*(.+?)\s+([\d.]+)\s+sec\s*$",
    )
    .expect("invalid ctest result regex")
});
static RESULT_PREFIX_RE: LazyLock<Regex> = LazyLock::new(|| {
    Regex::new(r"^\s*(?:\d+/\d+\s+)?Test\s+#\d+:").expect("invalid ctest result prefix regex")
});
static RESULT_TERMINATOR_RE: LazyLock<Regex> = LazyLock::new(|| {
    Regex::new(r"[\d.]+\s+sec\s*$").expect("invalid ctest result terminator regex")
});
static START_RE: LazyLock<Regex> = LazyLock::new(|| {
    Regex::new(r"^\s*Start\s+(\d+):\s*(.*?)\s*$").expect("invalid ctest start regex")
});
static SUMMARY_RE: LazyLock<Regex> = LazyLock::new(|| {
    Regex::new(r"^\s*\d+%\s+tests passed,\s+(\d+)\s+tests failed out of\s+(\d+)")
        .expect("invalid ctest summary regex")
});
static TIME_RE: LazyLock<Regex> = LazyLock::new(|| {
    Regex::new(r"^\s*Total Test time \(real\)\s+=\s+([\d.]+)\s+sec")
        .expect("invalid ctest time regex")
});

#[derive(Debug, Clone)]
struct TestCase {

View on GitHub (pinned to 0924356b4c)