dbt-labs/dbt-core · error · InvalidOperation

Compilation Error

Error message

Compilation Error: {message}

What it means

Same as the node-aware compilation error, but raised when `node_metadata_from_state` returns None — the rendering context has no node id/file path. The library then emits a plain `Compilation Error: {message}` so the user message still surfaces even without node context (e.g. rendering snippets outside a node).

Solutions

  1. Fix the condition described in `{message}` in the offending template/macro
  2. Render within a normal node context if node-level diagnostics are needed
  3. Replace the hard raise with `exceptions.warn` while debugging

Example fix

// before
{{ exceptions.raise_compiler_error("bad input") }}
// after
{% if bad_input %}{{ log("bad input: " ~ input, info=True) }}{% endif %}  // soften while diagnosing
Defensive patterns

Strategy: try-catch

Try / catch

// Same message shape without node info:
if let Some(msg) = err.to_string().strip_prefix("Compilation Error: ") {
    handle_compiler_error(msg);
}

Prevention

When it happens

Trigger: A template calls `raise_compiler_error(msg)` while being rendered without node metadata in the Jinja state (ad-hoc rendering, macro evaluation outside a model context).

Common situations: Running `dbt compile`/render of standalone macros or docs blocks where no model node is attached, yet a template-level validation failed.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of dbt-labs/dbt-core@0267ce9170 (2026-09-07). Data as JSON: /api/errors/50d95c7522807975. Report an issue: GitHub.

Appendix: source

Thrown at crates/dbt-jinja-utils/src/functions/base.rs:1145

                Ok(Value::UNDEFINED)
            }
            // (msg, node=None)
            "raise_compiler_error" => {
                let mut args = ArgParser::new(args, None);
                let message = args.get::<String>("msg")?;
                if let Some((node_id, file_path)) = node_metadata_from_state(state) {
                    Err(Error::new(
                        ErrorKind::InvalidOperation,
                        format!(
                            "Compilation Error for {} from {}: {}",
                            node_id,
                            file_path.display(),
                            message
                        ),
                    ))
                } else {
                    Err(Error::new(
                        ErrorKind::InvalidOperation,
                        format!("Compilation Error: {message}"),
                    ))
                }
            }
            // (msg) String
            "raise_not_implemented" => {
                let mut args = ArgParser::new(args, None);
                let message = args.get::<String>("msg")?;
                Err(Error::new(
                    ErrorKind::InvalidOperation,
                    format!("Not implemented: {message}"),
                ))
            }
            // (relation, expected_type, model=None)
            //   Relation,  String
            "relation_wrong_type" => {
                let mut args = ArgParser::new(args, None);

View on GitHub (pinned to 0267ce9170)