{"record":{"id":"3210aec479d856af","repo":"dbt-labs/dbt-core","slug":"error-always-present-on-shouldbe-butisnt-variant","errorCode":null,"errorMessage":"Error always present on ShouldBe::ButIsnt variant","messagePattern":"Error always present on ShouldBe::ButIsnt variant","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/dbt-parser/src/dbt_project_config.rs","lineNumber":117,"sourceCode":"\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\n                    ));\n                    emit_strict_parse_error(fs_err, dependency_package_name);\n                }\n            }\n        };\n        if !disallow_plus_prefix {\n            warn_plus_prefixed_resource_paths::<S>(\"\", configs, \"\", false);\n        }\n        Ok(recur_build_dbt_project_config(\n            dbt_config,\n            configs,\n            \"\",\n            &on_error,","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-parser/src/dbt_project_config.rs#L99-L135","documentation":"A panic from `.expect()` in `try_new` immediately after the message rewrite: the code takes ownership of the error (`take_err()`) stored on a `ShouldBe::ButIsnt` variant and asserts it is always present. This error is then converted into a richer `Invalid <type> definition` fs error. The panic signals the same ShouldBe invariant was broken at the error-value level.","triggerScenarios":"Same path as the sibling expect: YAML config key deserialization produces `ShouldBe::ButIsnt` whose `take_err()` returns None while building the 'Invalid <S::type_name> definition' error.","commonSituations":"Only observed when internal serde plumbing constructs ButIsnt without carrying an error; typically after refactors of dbt_jinja_utils::serde or custom deserializers feeding project config parsing.","solutions":["Fix the producer so ButIsnt always carries an Err value","Reproduce with the offending YAML key to identify which deserializer drops the error","Upgrade/pin dbt-jinja-utils to a fixed version","Replace the expect with a graceful fallback error to keep config parsing failing with a report instead of panicking"],"exampleFix":"// before\nlet err = variant.take_err().expect(\"Error always present on ShouldBe::ButIsnt variant\");\n\n// after\nlet err = variant.take_err()\n    .unwrap_or_else(|| DbtError::new(ErrorCode::InvalidConfigError, \"invalid value\"));","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"let err = variant.take_err().unwrap_or_else(|| {\n    DbtError::new(ErrorCode::InvalidConfigError, \"invalid value\")\n});","preventionTips":["Ensure every ShouldBe::ButIsnt construction carries an error value","Test config parsing with unknown keys to keep the error path exercised","Pin crate versions together when upgrading"],"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"}