{"record":{"id":"d861c9361acc0e38","repo":"rtk-ai/rtk","slug":"invalid-nextest-starting-regex","errorCode":null,"errorMessage":"invalid nextest starting regex","messagePattern":"invalid nextest starting regex","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmds/rust/cargo_cmd.rs","lineNumber":639,"sourceCode":"    }\n    let mut block = header.clone();\n    if !body.is_empty() {\n        block.push('\\n');\n        block.push_str(&body.join(\"\\n\"));\n    }\n    failures.push(block);\n    header.clear();\n    body.clear();\n}\n\n/// Filter cargo nextest output - show failures + compact summary\nfn filter_cargo_nextest(output: &str) -> String {\n    let summary_re = regex::Regex::new(\n        r\"Summary \\[\\s*([\\d.]+)s\\]\\s+(\\d+) tests? run:\\s+(\\d+) passed(?:,\\s+(\\d+) failed)?(?:,\\s+(\\d+) skipped)?\"\n    ).expect(\"invalid nextest summary regex\");\n\n    let starting_re = regex::Regex::new(r\"Starting \\d+ tests? across (\\d+) binar(?:y|ies)\")\n        .expect(\"invalid nextest starting regex\");\n\n    let mut failures: Vec<String> = Vec::new();\n    let mut in_failure_block = false;\n    let mut past_summary = false;\n    let mut current_failure_header = String::new();\n    let mut current_failure_body = Vec::new();\n    let mut summary_line = String::new();\n    let mut binaries: u32 = 0;\n    let mut has_cancel_line = false;\n\n    for line in output.lines() {\n        let trimmed = line.trim();\n\n        // Strip compilation noise\n        if trimmed.starts_with(\"Compiling\")\n            || trimmed.starts_with(\"Downloading\")\n            || trimmed.starts_with(\"Downloaded\")\n            || trimmed.starts_with(\"Finished\")","sourceCodeStart":621,"sourceCodeEnd":657,"githubUrl":"https://github.com/rtk-ai/rtk/blob/0924356b4caba4989607227b7c8824d3d8098719/src/cmds/rust/cargo_cmd.rs#L621-L657","documentation":"Panic from `.expect(\"invalid nextest starting regex\")` after `regex::Regex::new` for the `Starting N tests across M binaries` pattern in `filter_cargo_nextest` (src/cmds/rust/cargo_cmd.rs). Same class as the summary-regex panic: the regex crate rejects a syntactically invalid pattern and the expect converts it into an abort on the first invocation of the filter.","triggerScenarios":"A syntax error introduced into the hardcoded starting-line pattern (e.g. `binar(?:y|ies)` group corrupted, dangling `\\d+` escape, unclosed alternation); the panic surfaces when `filter_cargo_nextest` is first called by its unit tests.","commonSituations":"Manual edits matching a new cargo-nextest banner format, copy-paste mistakes breaking the `(?:y|ies)` group, or accidental removal of a closing parenthesis during refactoring.","solutions":["Correct the regex literal syntax and re-run `cargo test filter_cargo_nextest`.","Move the regex into a `LazyLock<Regex>` static so compilation happens once and never on the per-call hot path.","Adopt the fallback pattern (return a Result and run the raw command) if regex construction can ever fail at runtime."],"exampleFix":"// before\nlet starting_re = regex::Regex::new(r\"Starting \\d+ tests? across (\\d+) binar(?:y|ies)\")\n    .expect(\"invalid nextest starting regex\");\n// after\nstatic STARTING_RE: LazyLock<Regex> = LazyLock::new(|| {\n    Regex::new(r\"Starting \\d+ tests? across (\\d+) binar(?:y|ies)\")\n        .expect(\"invalid nextest starting regex\")\n});","handlingStrategy":"try-catch","validationCode":"// validate every hardcoded pattern at startup or in tests\n#[test]\nfn starting_regex_is_valid() {\n    regex::Regex::new(r\"Starting \\d+ tests? across (\\d+) binar(?:y|ies)\").unwrap();\n}","typeGuard":null,"tryCatchPattern":"let starting_re = match regex::Regex::new(STARTING_PAT) {\n    Ok(re) => re,\n    Err(e) => panic!(\"invalid nextest starting regex: {e}\"), // keep message\n};","preventionTips":["Keep regex construction in LazyLock statics per repo rules","Preserve the regex crate's error text in the panic message","Check balanced groups after editing alternations like (?:y|ies)"],"tags":["rust","regex","panic"],"backgroundTag":"invalid-regex-pattern","analyzedSha":"0924356b4caba4989607227b7c8824d3d8098719","analyzedAt":"2026-09-19T19:25:29.612Z","contentChangedAt":"2026-09-19T19:25:29.612Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}