Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Concept
-
Easy to imagine behavior
-
Minimum to remember
-
All usage and examples are documented in docstring
-
(require '[merr.core :as merr]) ;; => nil ;; for ClojureScript ;; (require '[merr.core :as merr :include-macros true]) (merr/let +err+ [foo 1 bar (merr/error) baz (* bar 2)] {:+err+ +err+ :foo foo :bar bar :baz baz}) ;; => {:+err+ (merr/error), :foo 1, :bar nil, :baz nil}
Usage
let
(merr/let err [a 10 b (inc a) c (inc b)] (if err (merr/message err) (str "c = " c))) ;; => "c = 12" (merr/let err [a 10 b (merr/error {:message "ERROR"}) c (inc b)] (if err (merr/message err) (str "c = " c))) ;; => "ERROR"
Custom error
You can specify any keywords as :type, but you may want to define and use specific :type of errors in your project.
In that case, merr.helper is useful.
(require '[merr.helper :as merr.h]) ;; => nil (def custom-error (partial merr.h/typed-error ::custom-error-type)) ;; => var? (def custom-error? (partial merr.h/typed-error? ::custom-error-type)) ;; => var? (custom-error? (custom-error {:message "custom error"})) ;; => true
typed-error? will check child error types, so you can define sub errors via clojure.core/derive.
(derive ::sub-custom-error-type ::custom-error-type) ;; => nil (custom-error? (merr/error {:type ::sub-custom-error-type})) ;; => true