{"record":{"id":"67df6f3df1d1e794","repo":"dbt-labs/dbt-core","slug":"valid-regex-67df6f","errorCode":null,"errorMessage":"valid regex","messagePattern":"valid regex","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/dbt-adapter/src/time_machine/validation.rs","lineNumber":441,"sourceCode":"    }\n}\n\n/// Apply all sanitizers to a SQL string.\nfn apply_sanitizers(sql: &str, sanitizers: &[Box<dyn SqlSanitizer>]) -> String {\n    let mut result = sql.to_string();\n    for sanitizer in sanitizers {\n        result = sanitizer.sanitize(&result);\n    }\n    result\n}\n\n// TODO(jason): A real SQL formatter...\n/// Format normalized SQL for readable diff display by looking at certain keywords\nfn format_sql_for_display(normalized_sql: &str) -> String {\n    static RE: LazyLock<Regex> = LazyLock::new(|| {\n        Regex::new(\n            r\"(?i)\\b(SELECT|FROM|WHERE|AND|OR|JOIN|LEFT JOIN|RIGHT JOIN|INNER JOIN|OUTER JOIN|CROSS JOIN|ON|GROUP BY|ORDER BY|HAVING|LIMIT|OFFSET|UNION|INTERSECT|EXCEPT|WITH|AS \\(|INSERT|UPDATE|DELETE|CREATE|ALTER|DROP|COPY GRANTS|VALUES)\\b\"\n        ).expect(\"valid regex\")\n    });\n\n    RE.replace_all(normalized_sql, \"\\n$1\").trim().to_string()\n}\n\n// ============================================================================\n// Deviations\n// ============================================================================\n\n/// Deviation for dbt_pov_model_cost_calculator package.\n///\n/// This package generates dynamic SQL with:\n/// - Execution times\n/// - Timestamps\n/// - Invocation IDs\n/// - Run IDs\npub struct DbtPovModelCostCalculatorDeviation;\n","sourceCodeStart":423,"sourceCodeEnd":459,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-adapter/src/time_machine/validation.rs#L423-L459","documentation":"Panic from `Regex::new(...).expect(\"valid regex\")` inside `format_sql_for_display` in crates/dbt-adapter/src/time_machine/validation.rs:441. The function builds a LazyLock regex that inserts newlines before SQL keywords for readable diffs; a panic here means the hard-coded pattern failed to compile. Because it is a compile-time constant pattern, this can only happen if the pattern string is edited incorrectly — it is an internal invariant, not user input.","triggerScenarios":"Editing the static regex literal in format_sql_for_display with an unbalanced group, bad escape (e.g. `\\b` typo, stray `\\(`), or an unsupported syntax for the `regex` crate version in use; the panic then fires on first use during ValidationMismatch diff formatting or test_format_sql_for_display.","commonSituations":"Adding a new SQL keyword to the alternation and accidentally breaking the `(?i)\\b(...)\\b` structure; regex crate upgrade that rejects previously-permissive syntax (e.g. duplicated group names, invalid escapes).","solutions":["Paste the literal pattern into a regex validator (regex101 with Rust flavor) and fix the syntax error at the reported position.","Check parentheses balance in the `(?i)\\b(...)\\b` group after recent edits.","Escape any literal parentheses or backslashes you intended to match (e.g. the `AS \\(` intent).","Convert the expect to a LazyLock built via OnceLock with a fallback plain-string formatter so bad patterns degrade instead of panicking."],"exampleFix":"// before\nRegex::new(\n    r\"(?i)\\b(SELECT|FROM|...|AS \\(|VALUES)\\b\"\n).expect(\"valid regex\")\n// after (verify alternation/group balance)\nRegex::new(\n    r\"(?i)\\b(SELECT|FROM|WHERE|AND|OR|JOIN|LEFT JOIN|RIGHT JOIN|INNER JOIN|OUTER JOIN|CROSS JOIN|ON|GROUP BY|ORDER BY|HAVING|LIMIT|OFFSET|UNION|INTERSECT|EXCEPT|WITH|INSERT|UPDATE|DELETE|CREATE|ALTER|DROP|COPY GRANTS|VALUES)\\b|(?i)\\bAS\\s*\\(\"\n).expect(\"valid regex\")","handlingStrategy":"try-catch","validationCode":"fn sql_display_regex_valid() -> bool {\n    Regex::new(SQL_DISPLAY_PATTERN).is_ok()\n}","typeGuard":"null","tryCatchPattern":"static RE: LazyLock<Option<Regex>> = LazyLock::new(|| {\n    Regex::new(SQL_DISPLAY_PATTERN).map_err(|e| { log::error(\"sql display regex invalid: {e}\"); e }).ok()\n});\n// fall back to plain normalized_sql when RE is None","preventionTips":["Validate regex literals with a Rust-flavor checker in CI.","Keep the pattern in a named constant with a unit test asserting Regex::new(...).is_ok().","Escaped constructs like AS \\( deserve their own alternation branch with a test."],"tags":["rust","regex","sql-formatting","panic"],"backgroundTag":"invalid-regex-pattern","analyzedSha":"0267ce9170576975b76b64ce856b2e5848e96617","analyzedAt":"2026-09-07T21:53:39.732Z","contentChangedAt":"2026-09-07T21:53:39.732Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}