Liking cljdoc? Tell your friends :D

io.julienvincent.malt.error


?ErrorDefinitionclj

A malli schema representing the format for a malt error definition.

Can be referenced directly if you want to validate definitions, or you can use the provided [validate-definition!] fn.

A malli schema representing the format for a malt error definition.

Can be referenced directly if you want to validate definitions, or you can
use the provided [validate-definition!] fn.
sourceraw docstring

exclj

(ex code|definition)
(ex code|definition message|data)
(ex code|definition message|data data|cause)
(ex code|definition message data cause)

Constructs a clojure.lang.ExceptionInfo representing a malt error.

The first argument is either a keyword error code or an error definition map (see [?ErrorDefinition]) containing at minimum a :code. Remaining arguments are interpreted by type:

  • A string is treated as the exception message
  • A map is treated as the exception data
  • A Throwable is treated as the exception cause

A message must always be resolvable - either passed explicitly as a string, or present as :message on the definition. When both are provided, the explicit string takes precedence.

The resulting exception carries {:type :malt/error :code code :data data} as its ex-data.

Usage:

(def not-found
  {:code :not-found
   :message "Resource not found"})

;; From a definition containing a :message
(ex not-found)

;; Code or definition with an explicit message
(ex :not-found "Resource not found")

;; Definition with data, message taken from the definition
(ex not-found {:id "123"})

;; Message and data
(ex :not-found "Resource not found" {:id "123"})

;; Message and cause
(ex :not-found "Resource not found" cause)

;; Definition with data and cause, message taken from the definition
(ex not-found {:id "123"} cause)

;; All arguments explicitly
(ex :not-found "Resource not found" {:id "123"} cause)

Throws an IllegalArgumentException when no message can be resolved, when the definition contains no :code, or when an argument has an unexpected type.

Constructs a `clojure.lang.ExceptionInfo` representing a malt error.

The first argument is either a keyword error `code` or an error `definition`
map (see [?ErrorDefinition]) containing at minimum a `:code`. Remaining
arguments are interpreted by type:

- A string is treated as the exception message
- A map is treated as the exception data
- A Throwable is treated as the exception cause

A message must always be resolvable - either passed explicitly as a string,
or present as `:message` on the definition. When both are provided, the
explicit string takes precedence.

The resulting exception carries `{:type :malt/error :code code :data data}`
as its `ex-data`.

Usage:

```clojure
(def not-found
  {:code :not-found
   :message "Resource not found"})

;; From a definition containing a :message
(ex not-found)

;; Code or definition with an explicit message
(ex :not-found "Resource not found")

;; Definition with data, message taken from the definition
(ex not-found {:id "123"})

;; Message and data
(ex :not-found "Resource not found" {:id "123"})

;; Message and cause
(ex :not-found "Resource not found" cause)

;; Definition with data and cause, message taken from the definition
(ex not-found {:id "123"} cause)

;; All arguments explicitly
(ex :not-found "Resource not found" {:id "123"} cause)
```

Throws an `IllegalArgumentException` when no message can be resolved, when
the definition contains no `:code`, or when an argument has an unexpected
type.
sourceraw docstring

throw!clj

(throw! code|definition)
(throw! code|definition message|data)
(throw! code|definition message|data data|cause)
(throw! code|definition message data cause)

Constructs and immediately throws a malt error.

Accepts the same arguments as [ex] - see its docstring for the full set of supported call shapes.

(def not-found
  {:code :not-found
   :message "Resource not found"})

(throw! not-found)
(throw! :not-found "Resource not found")
(throw! :not-found "Resource not found" {:id "123"} cause)
Constructs and immediately throws a malt error.

Accepts the same arguments as [ex] - see its docstring for the full set of
supported call shapes.

```clojure
(def not-found
  {:code :not-found
   :message "Resource not found"})

(throw! not-found)
(throw! :not-found "Resource not found")
(throw! :not-found "Resource not found" {:id "123"} cause)
```
sourceraw docstring

validate-definition!clj

(validate-definition! definition)

Validate that a given malt error definition conforms to the malt error definition schema format.

Validate that a given malt error `definition` conforms to the malt error
definition schema format.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close