dbt-labs/dbt-core · error
invalid cli error code
Error message
invalid cli error code: {frontend_code} What it means
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.
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
Example fix
// before
Self::try_from(frontend_code).expect("invalid cli error code: {frontend_code}")
// after
Self::try_from(frontend_code)
.unwrap_or_else(|_| {
tracing::error!(code = frontend_code, "unmapped frontend error code");
Self::Internal
}) Defensive patterns
Strategy: validation
Validate before calling
fn is_valid_cli_code(frontend_code: u16) -> bool {
ErrorCode::try_from(frontend_code).is_ok()
}
// assert every dbt_frontend_common::ErrorCode variant maps before calling From
assert!(is_valid_cli_code(code as u16)); Prevention
- 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
When it happens
Trigger: 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)`.
Common situations: 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.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- failed to generate unique thread ID: bitspace exhausted
- inconsistent park_timeout state
- inconsistent state in unpark
- jsonify_nested_columns: rewritten schema and columns are…
- string prefix checked
AI-assisted analysis of dbt-labs/dbt-core@0267ce9170 (2026-09-07).
Data as JSON: /api/errors/73943746ca925484.
Report an issue: GitHub.
Appendix: source
Thrown at crates/dbt-error/src/codes.rs:404
ErrorCode::DbConnectionFailed
| ErrorCode::DbAuthFailed
| ErrorCode::DbSyntaxInvalid
| ErrorCode::DbResourceExceeded
| ErrorCode::DbUnavailable
| ErrorCode::DbTxnConflict
| ErrorCode::DbNotFound
| ErrorCode::DbUnsupportedFeature
| ErrorCode::DbDriverFailed
| ErrorCode::ExecutorFailed
)
}
}
impl From<dbt_frontend_common::error::ErrorCode> for ErrorCode {
fn from(code: dbt_frontend_common::error::ErrorCode) -> Self {
let frontend_code = code as u16;
if frontend_code < dbt_frontend_common::error::ErrorCode::NotSupported as u16 {
Self::try_from(frontend_code).expect("invalid cli error code: {frontend_code}")
} else {
// Internal errors map to the 9k range:
Self::try_from(frontend_code + 9000).expect("invalid cli error code: {frontend_code}")
}
}
}
/// General warning handling. Warnings are controlled via -w from the CLI.
///
/// Warnings can be set and unset. They are usually passed as part of EvalArg.
///
/// A warning is active if its key in the Warnings hashmap is defined.
/// The value of the key can be used to provide additional info, for instance
/// for the warning capitalization_identifier:upper, use the error code for
/// capitalization_identifier as key and the string "upper" as value.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Warnings {
// todo: better representation, but good enough for now...
pub values: HashMap<ErrorCode, String>,View on GitHub (pinned to 0267ce9170)