Skip to main content

About exceptions namespace

The exceptions namespace can be used to raise warnings and errors in dbt userspace.

raise_compiler_error

The exceptions.raise_compiler_error method will raise a compiler error with the provided message. This is typically only useful in macros or materializations when invalid arguments are provided by the calling model. Note that throwing an exception will cause a model to fail, so please use this variable with care!

Example usage:

exceptions.sql
{% if number < 0 or number > 100 %}
{{ exceptions.raise_compiler_error("Invalid `number`. Got: " ~ number) }}
{% endif %}

warn

Use the exceptions.warn method to raise a compiler warning with the provided message, but any model will still be successful and be treated as a PASS. By default, warnings will not cause dbt runs to fail. However:

  • If you use the --warn-error flag, all warnings will be promoted to errors.
  • To promote only Jinja warnings to errors (and leave other warnings alone), use --warn-error-options. For example, --warn-error-options '{"error": ["JinjaLogWarning"]}'.

Learn more about Warnings.

Example usage:

warn.sql
{% if number < 0 or number > 100 %}
{% do exceptions.warn("Invalid `number`. Got: " ~ number) %}
{% endif %}
0