A hierarchy of all QP error types. Ideally all QP exceptions should be ex-data maps with an :type key whose value is one of the types here. If you see an Exception in QP code that doesn't return an :type, add it!

(throw (ex-info (tru "Don''t know how to parse {0} {1}" (class x) x) {:type qp.error-type/invalid-parameter}))

(ns metabase.query-processor.error-type)
(def ^:private hierarchy
  (make-hierarchy))

Is error-type a known QP error type (i.e., one defined with deferror above)?

(defn known-error-type?
  [error-type]
  (isa? hierarchy error-type :error))

Should errors of this type be shown to users of Metabase in embedded Cards or Dashboards? Normally, we return a generic 'Query Failed' error message for embedded queries, so as not to leak information. Some errors (like missing parameter errors), however, should be shown even in these situations.

(defn show-in-embeds?
  [error-type]
  (isa? hierarchy error-type :show-in-embeds?))
(defmacro ^:private deferror
  {:style/indent 1}
  [error-name docstring & {:keys [parent show-in-embeds?]}]
  {:pre [(some? parent)]}
  `(do
     (def ~error-name ~docstring ~(keyword error-name))
     (alter-var-root #'hierarchy derive ~(keyword error-name) ~(keyword parent))
     ~(when show-in-embeds?
        `(alter-var-root #'hierarchy derive ~(keyword error-name) :show-in-embeds?))))

Client Errors

Generic ancestor type for all errors with the query map itself. Equivalent of a HTTP 4xx status code.

(deferror client
  :parent :error)

Is error-type a client error type, the equivalent of an HTTP 4xx status code?

(defn client-error?
  [error-type]
  (isa? hierarchy error-type :client))

The current user does not have required permissions to run the current query.

(deferror missing-required-permissions
  :parent client)

Something related to configuration (e.g. of a sandbox/GTAP) is preventing us from being able to run the query.

(deferror bad-configuration
  :parent client)

Generic ancestor type for errors with the query map itself.

(deferror invalid-query
  :parent client)

The query is parameterized, and a required parameter was not supplied.

(deferror missing-required-parameter
  :parent invalid-query
  :show-in-embeds? true)

The query is parameterized, and a supplied parameter has an invalid value.

(deferror invalid-parameter
  :parent invalid-query
  :show-in-embeds? true)

The query is using a feature that is not supported by the database/driver.

(deferror unsupported-feature
  :parent invalid-query
  :show-in-embeds? true)

The query is using a feature that is disabled globally.

(deferror disabled-feature
  :parent invalid-query
  :show-in-embeds? true)

Server-Side Errors

Generic ancestor type for all unexpected server-side errors. Equivalent of a HTTP 5xx status code.

(deferror server
  :parent :error)

Error type if query fails to return the first row of results after some timeout.

(deferror timed-out
  :parent server
  :show-in-embeds? true)

QP Errors

Generic ancestor type for all unexpected errors (e.g., uncaught Exceptions) in Query Processor code.

(deferror qp
  :parent server)

Generic ancestor type for all unexpected errors related to bad drivers and uncaught Exceptions in driver code.

(deferror driver
  :parent qp)

Data Warehouse (DB) Errors

Generic ancestor type for all unexpected errors returned or thrown by a data warehouse when running a query.

(deferror db
  :parent server)