{"record":{"id":"f422ae579c39bec6","repo":"rtk-ai/rtk","slug":"invalid-ctest-result-regex","errorCode":null,"errorMessage":"invalid ctest result regex","messagePattern":"invalid ctest result regex","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmds/system/ctest_cmd.rs","lineNumber":28,"sourceCode":"use crate::core::runner::{self, RunOptions};\nuse crate::core::truncate::{self, CAP_LIST, CAP_WARNINGS};\nuse crate::core::utils::{resolved_command, strip_ansi};\n\nconst MAX_SLOWEST: usize = 3;\nconst MAX_FAILURE_LINES: usize = CAP_WARNINGS;\nconst MAX_FAILURE_HEAD_LINES: usize = 2;\nconst MAX_FAILED_LIST_LINES: usize = CAP_LIST;\nconst MAX_DETECT_PREAMBLE_LINES: usize = 4;\n// Failure entries carry a header plus up to `MAX_FAILURE_LINES` detail lines each,\n// so this list deviates below `CAP_LIST`; the single-line skipped and raw-trailer\n// lists keep the full cap.\nconst MAX_FAILED_BLOCK_ENTRIES: usize = truncate::reduced(CAP_LIST, 5);\n\nstatic TEST_RE: LazyLock<Regex> = LazyLock::new(|| {\n    Regex::new(\n        r\"(?s)^\\s*(?:\\d+/(\\d+)\\s+)?Test\\s+#(\\d+):\\s+(.+?)\\s+\\.{2,}\\s*(?:\\*{3})?\\s*(.+?)\\s+([\\d.]+)\\s+sec\\s*$\",\n    )\n    .expect(\"invalid ctest result regex\")\n});\nstatic RESULT_PREFIX_RE: LazyLock<Regex> = LazyLock::new(|| {\n    Regex::new(r\"^\\s*(?:\\d+/\\d+\\s+)?Test\\s+#\\d+:\").expect(\"invalid ctest result prefix regex\")\n});\nstatic RESULT_TERMINATOR_RE: LazyLock<Regex> = LazyLock::new(|| {\n    Regex::new(r\"[\\d.]+\\s+sec\\s*$\").expect(\"invalid ctest result terminator regex\")\n});\nstatic START_RE: LazyLock<Regex> = LazyLock::new(|| {\n    Regex::new(r\"^\\s*Start\\s+(\\d+):\\s*(.*?)\\s*$\").expect(\"invalid ctest start regex\")\n});\nstatic SUMMARY_RE: LazyLock<Regex> = LazyLock::new(|| {\n    Regex::new(r\"^\\s*\\d+%\\s+tests passed,\\s+(\\d+)\\s+tests failed out of\\s+(\\d+)\")\n        .expect(\"invalid ctest summary regex\")\n});\nstatic TIME_RE: LazyLock<Regex> = LazyLock::new(|| {\n    Regex::new(r\"^\\s*Total Test time \\(real\\)\\s+=\\s+([\\d.]+)\\s+sec\")\n        .expect(\"invalid ctest time regex\")\n});","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/rtk-ai/rtk/blob/0924356b4caba4989607227b7c8824d3d8098719/src/cmds/system/ctest_cmd.rs#L10-L46","documentation":"Panic from `.expect(\"invalid ctest result regex\")` in a `LazyLock<Regex>` initializer in src/cmds/system/ctest_cmd.rs:28. The ctest filter compiles its per-test result-line regex once; if the pattern is syntactically invalid, the regex crate returns `Err`, the expect panics, and the module fails during first use (module-init failure) before any ctest output can be filtered.","triggerScenarios":"A syntax error in the hardcoded multi-line result pattern — e.g. the `(?s)` flag position, the `(?:\\*{3})?` optional group, or a `\\.{2,}` repetition escape being corrupted — triggers the panic at static initialization.","commonSituations":"Editing the pattern to match a new CMake/ctest result-line format and misplacing `(?s)` or a quantifier; because these are LazyLock statics, the failure manifests as an instant crash on the first filter call rather than at compile time.","solutions":["Fix the regex literal — verify `(?s)` is at the start, all groups `(?: ... )` are balanced, and escapes like `\\.` and `\\s` are intact.","Keep it in LazyLock (correct per repo rules) but validate the pattern with a unit test that touches the static so CI catches it before release.","For resilience, prefer `Regex::new(...).unwrap_or_else(|e| panic!(\"invalid ctest result regex: {e}\"))` so the syntax error message is preserved."],"exampleFix":"// before\n.expect(\"invalid ctest result regex\")\n// after\n.unwrap_or_else(|e| panic!(\"invalid ctest result regex: {e} in pattern: {PAT}\"))","handlingStrategy":"try-catch","validationCode":"// force static init in a test so bad regexes fail CI\n#[test]\nfn ctest_regexes_initialize() {\n    LazyLock::force(&TEST_RE);\n    LazyLock::force(&RESULT_PREFIX_RE);\n    LazyLock::force(&RESULT_TERMINATOR_RE);\n}","typeGuard":null,"tryCatchPattern":"Regex::new(PAT).unwrap_or_else(|e| panic!(\"invalid ctest result regex: {e}\"))","preventionTips":["Touch all LazyLock regexes from at least one unit test","Place flags like (?s) first and verify quantifier escapes (\\.{2,}) after edits","Include the pattern text in panic messages for fast diagnosis"],"tags":["rust","regex","ctest"],"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"}