{"record":{"id":"ce4eb143e9e3af93","repo":"dbt-labs/dbt-core","slug":"valid-regex","errorCode":null,"errorMessage":"valid regex","messagePattern":"valid regex","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"info","filePath":"crates/dbt-adapter/src/metadata/snowflake/mod.rs","lineNumber":315,"sourceCode":"                last_altered,\n                (table_type = 'VIEW' OR table_type = 'MATERIALIZED VIEW') AS is_view\n             FROM {}.INFORMATION_SCHEMA.TABLES\n             WHERE {}\",\n        database,\n        where_clauses.join(\" OR \")\n    ))\n}\n\nfn is_table_ddl(ddl: &str) -> bool {\n    static TABLE_REGEX: Lazy<fancy_regex::Regex> = Lazy::new(|| {\n        fancy_regex::Regex::new(\n            r\"(?ix)\n                ^\\s*create\\b\n                (?:\\s+(?!table\\b)\\w+)*\n                \\s+table\\b\n                \",\n        )\n        .expect(\"valid regex\")\n    });\n\n    if ddl.trim().is_empty() {\n        return false;\n    }\n    // `is_match` returns Result because fancy-regex's backtracking engine\n    // can fail on pathological inputs; treat any engine error as \"not a\n    // table\" so a malformed DDL doesn't get cached as a view by mistake.\n    TABLE_REGEX.is_match(ddl).unwrap_or(false)\n}\n\n/// Render the anonymous block (the body that goes inside `EXECUTE IMMEDIATE $$...$$`)\n/// that calls `GET_DDL` over a list of FQNs and captures per-object errors as\n/// part of the result set.\n///\n/// The caller is responsible for wrapping the returned string in\n/// `EXECUTE IMMEDIATE $$ ... $$`. The rendered block accepts no parameters\n/// and returns a result set with columns (fqn, view_definition, error).","sourceCodeStart":297,"sourceCodeEnd":333,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-adapter/src/metadata/snowflake/mod.rs#L297-L333","documentation":"`is_table_ddl` (crates/dbt-adapter/src/metadata/snowflake/mod.rs:315) compiles a static `fancy_regex` pattern once and calls `.expect(\"valid regex\")`. Because the pattern is a hardcoded literal, the panic is unreachable unless the source regex was edited and no longer compiles — it is a compile-time-style invariant guard.","triggerScenarios":"Only when the embedded regex literal in the source is modified into an invalid pattern (unbalanced groups, bad syntax for fancy-regex's backtracking engine).","commonSituations":"Contributors editing the DDL-detection regex with a syntax error; fancy-regex version changes that reject previously-accepted syntax (rare).","solutions":["Fix the regex literal syntax that fails to compile (check parentheses, lookahead syntax)","Add a unit test that compiles the pattern so regressions are caught in CI instead of at runtime","Pin/upgrade fancy-regex if a version change altered accepted syntax"],"exampleFix":"// before\n.expect(\"valid regex\")\n// after\n.unwrap_or_else(|e| panic!(\"invalid DDL regex literal: {e}\")) // plus a #[test] that builds it\n","handlingStrategy":"validation","validationCode":"// compile-time guard in tests\n#[test]\nfn ddl_regex_compiles() {\n    fancy_regex::Regex::new(r\"(?ix)^\\s*create\\b(?:\\s+(?!table\\b)\\w+)*\\s+table\\b\").unwrap();\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Add unit tests compiling all static regex literals","Validate regex edits with the fancy-regex crate docs","Keep regex literals simple; prefer split patterns over exotic syntax","Pin fancy-regex version in Cargo.lock"],"tags":["rust","regex","static-pattern","snowflake"],"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-14T16:17:12.679Z"}