mirror of
https://github.com/penpot/penpot.git
synced 2025-05-29 23:16:11 +02:00
🚧 Initial work on replace struct with spec.
This commit is contained in:
parent
97220d707b
commit
5afbfe1ce9
4 changed files with 127 additions and 49 deletions
|
@ -5,16 +5,27 @@
|
|||
;; Copyright (c) 2016 Andrey Antukh <niwi@niwi.nz>
|
||||
|
||||
(ns uxbox.util.exceptions
|
||||
"A helpers for work with exceptions.")
|
||||
"A helpers for work with exceptions."
|
||||
(:require [clojure.spec.alpha :as s]))
|
||||
|
||||
(s/def ::type keyword?)
|
||||
(s/def ::code keyword?)
|
||||
(s/def ::mesage string?)
|
||||
(s/def ::hint string?)
|
||||
(s/def ::cause #(instance? Exception %))
|
||||
(s/def ::error-params
|
||||
(s/keys :req-un [::type]
|
||||
:opt-un [::code
|
||||
::hint
|
||||
::mesage
|
||||
::cause]))
|
||||
|
||||
(defn error
|
||||
[& {:keys [type code message] :or {type :unexpected} :as payload}]
|
||||
{:pre [(keyword? type) (keyword? code)]}
|
||||
(let [message (if message
|
||||
(str message " / " (pr-str code) "")
|
||||
(pr-str code))
|
||||
payload (assoc payload :type type)]
|
||||
(ex-info message payload)))
|
||||
[& {:keys [type code message hint cause] :as params}]
|
||||
(s/assert ::error-params params)
|
||||
(let [message (or message hint "")
|
||||
payload (dissoc params :cause :message)]
|
||||
(ex-info message payload cause)))
|
||||
|
||||
(defmacro raise
|
||||
[& args]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue