{"record":{"id":"f563815d40ab23de","repo":"dbt-labs/dbt-core","slug":"error-message-always-present-on-shouldbe-butisnt","errorCode":null,"errorMessage":"Error message always present on ShouldBe::ButIsnt variant","messagePattern":"Error message always present on ShouldBe::ButIsnt variant","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/dbt-parser/src/dbt_project_config.rs","lineNumber":104,"sourceCode":"                            detail\n                        ),\n                    );\n                    emit_strict_parse_error(fs_err, dependency_package_name);\n                }\n                ShouldBe::ButIsnt(_) => {\n                    let filename = if let Some(raw) = variant.as_ref_raw()\n                        && let Some(filename) = raw.span().get_filename()\n                    {\n                        Some(filename)\n                    } else {\n                        None\n                    };\n\n                    // An unknown key produces the error message `expected struct <SelfType>` due to\n                    // the recursive type. Catch the error here to inject a more descriptive error.\n                    let err_msg = variant\n                        .as_err_msg()\n                        .expect(\"Error message always present on ShouldBe::ButIsnt variant\");\n                    let self_type = std::any::type_name::<S>()\n                        .rsplit(\"::\")\n                        .next()\n                        .unwrap_or_default();\n                    let detail = if err_msg.contains(&format!(\"expected struct {self_type}\")) {\n                        format!(\"Unrecognized key `{key_path}`. Custom keys must go under `+meta`.\")\n                    } else {\n                        err_msg.to_string()\n                    };\n\n                    let err = variant\n                        .take_err()\n                        .expect(\"Error always present on ShouldBe::ButIsnt variant\");\n                    let fs_err = yaml_to_fs_error(err, filename).with_context(format!(\n                        \"Invalid {} definition `{}`: {}\",\n                        S::type_name(),\n                        key_path,\n                        detail","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-parser/src/dbt_project_config.rs#L86-L122","documentation":"A panic from `.expect()` in `try_new` while validating dbt_project.yml/properties keys. When a key's deserialization fails with a `ShouldBe::ButIsnt` variant, the code expects an error message to always be present so it can rewrite the generic 'expected struct ...' message into 'Unrecognized key ...'. The panic means that invariant (ButIsnt always carries a message) was violated by the serde machinery.","triggerScenarios":"Deserializing a config struct `S` from YAML where an unknown/invalid key yields a `ShouldBe::ButIsnt` variant whose `as_err_msg()` returns None — a serde-layer invariant breach, not a user config problem.","commonSituations":"Practically only hit after internal changes to `dbt_jinja_utils::serde`'s ShouldBe/err plumbing, or via unusual deserializer paths that construct ButIsnt without a message while processing dbt_project.yml keys.","solutions":["Report/debug the serde helper: ensure every `ShouldBe::ButIsnt` is constructed with an error message","Inspect which key/type triggered it by reproducing with the same YAML and struct type","Pin/upgrade `dbt-jinja-utils` to a version where the ButIsnt invariant holds","As a workaround, wrap config parsing so the panic is converted into a proper error report"],"exampleFix":"// before\nlet err_msg = variant.as_err_msg().expect(\"Error message always present on ShouldBe::ButIsnt variant\");\n\n// after\nlet err_msg = variant.as_err_msg().unwrap_or_else(|| \"invalid value\".to_string());","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"let err_msg = match variant.as_err_msg() {\n    Some(m) => m,\n    None => return Err(fallback_error(\"unrecognized key\")),\n};","preventionTips":["Keep dbt-jinja-utils and dbt-parser versions in sync","Validate dbt_project.yml keys (+prefixed) before parsing in CI","Report ShouldBe invariant breaches upstream instead of patching locally"],"tags":["rust","serde","yaml","invariant","panic"],"backgroundTag":"internal-invariant-violation","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"}