{"record":{"id":"73943746ca925484","repo":"dbt-labs/dbt-core","slug":"invalid-cli-error-code-frontend-code","errorCode":null,"errorMessage":"invalid cli error code: {frontend_code}","messagePattern":"invalid cli error code: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/dbt-error/src/codes.rs","lineNumber":404,"sourceCode":"            ErrorCode::DbConnectionFailed\n                | ErrorCode::DbAuthFailed\n                | ErrorCode::DbSyntaxInvalid\n                | ErrorCode::DbResourceExceeded\n                | ErrorCode::DbUnavailable\n                | ErrorCode::DbTxnConflict\n                | ErrorCode::DbNotFound\n                | ErrorCode::DbUnsupportedFeature\n                | ErrorCode::DbDriverFailed\n                | ErrorCode::ExecutorFailed\n        )\n    }\n}\n\nimpl From<dbt_frontend_common::error::ErrorCode> for ErrorCode {\n    fn from(code: dbt_frontend_common::error::ErrorCode) -> Self {\n        let frontend_code = code as u16;\n        if frontend_code < dbt_frontend_common::error::ErrorCode::NotSupported as u16 {\n            Self::try_from(frontend_code).expect(\"invalid cli error code: {frontend_code}\")\n        } else {\n            // Internal errors map to the 9k range:\n            Self::try_from(frontend_code + 9000).expect(\"invalid cli error code: {frontend_code}\")\n        }\n    }\n}\n/// General warning handling. Warnings are controlled via -w from the CLI.\n///\n/// Warnings can be set and unset. They are usually passed as part of EvalArg.\n///\n/// A warning is active if its key in the Warnings hashmap is defined.\n/// The value of the key can be used to provide additional info, for instance\n/// for the warning capitalization_identifier:upper, use the error code for\n/// capitalization_identifier as key and the string \"upper\" as value.\n#[derive(Clone, Debug, PartialEq, Eq)]\npub struct Warnings {\n    // todo: better representation, but good enough for now...\n    pub values: HashMap<ErrorCode, String>,","sourceCodeStart":386,"sourceCodeEnd":422,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-error/src/codes.rs#L386-L422","documentation":"When converting a frontend ErrorCode into the CLI ErrorCode space via `From`, the numeric value is mapped through `try_from` and the result is unwrapped with `expect`. This panic fires when the frontend code's discriminant (below `NotSupported`) has no corresponding CLI error code defined. It is an internal invariant failure: the two enums in dbt-frontend-common and dbt-error are out of sync.","triggerScenarios":"A new variant is added to `dbt_frontend_common::error::ErrorCode` with a discriminant smaller than `NotSupported`, but the matching `u16 -> ErrorCode` TryFrom table in dbt-error's codes.rs is not updated. Any code then converts that frontend error via `ErrorCode::from(frontend_code)`.","commonSituations":"Cross-crate enum drift after a frontend error-code refactor; cherry-picking a change that adds a frontend variant into a branch whose CLI code table is older; hand-edited discriminant values in the frontend enum.","solutions":["Add the missing u16 mapping for the frontend code in the `TryFrom<u16>` impl for ErrorCode in crates/dbt-error/src/codes.rs","Confirm the frontend variant's discriminant is below `NotSupported`; if it is an internal error it should take the +9000 branch instead","Regenerate or resync the error-code tables from the shared definition so dbt-frontend-common and dbt-error agree","As a temporary measure, replace `expect` with a fallback mapping to a generic/internal CLI error code to avoid panicking in production"],"exampleFix":"// before\nSelf::try_from(frontend_code).expect(\"invalid cli error code: {frontend_code}\")\n// after\nSelf::try_from(frontend_code)\n    .unwrap_or_else(|_| {\n        tracing::error!(code = frontend_code, \"unmapped frontend error code\");\n        Self::Internal\n    })","handlingStrategy":"validation","validationCode":"fn is_valid_cli_code(frontend_code: u16) -> bool {\n    ErrorCode::try_from(frontend_code).is_ok()\n}\n// assert every dbt_frontend_common::ErrorCode variant maps before calling From\nassert!(is_valid_cli_code(code as u16));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Add a CI test round-tripping all frontend ErrorCode variants through the From impl","Keep the two enums' definitions in one generated source","Always update dbt-error when adding dbt-frontend-common variants","Avoid expect in From impls; fall back to a generic internal error code"],"tags":["panic","error-code-mapping","enum-drift","internal-invariant"],"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-17T15:17:12.973Z"}