Created
March 16, 2017 17:27
-
-
Save stuarthalloway/9084f92519694a925bdfa0874f34de4d to your computer and use it in GitHub Desktop.
Errors as data compose, error messages not so much
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; spec errors are data, and as such are composable with all the rest | |
;; of Clojure. The forms below show getting to an interesting part | |
;; of an error in a larger data structure, taking advantage of | |
;; edn-reading, pretty-printing, *print-length* and threading macro. | |
;; It is difficult to maintain the compositionality shown here | |
;; once you convert error data into e.g. ASCII art. | |
(require | |
'[clojure.edn :as edn] | |
'[clojure.pprint :as pp]) | |
(set! *print-length* 5) | |
(def error | |
(edn/read-string | |
{:readers {'error identity}} | |
(slurp "https://gist.githubusercontent.com/jjl/d44c38984dce72c9d083975f7b475e5a/raw/38dd260fff8c6001ecceb978a351179e3c2d1ba5/gistfile1.txt"))) | |
(-> error :data :explain :cljs.spec/problems first pp/pprint) | |
{:path [:paths], | |
:pred string?, | |
:val | |
[[0 -10 -3.3333333333333335] | |
[0 -9 -3] | |
[0 -8 -2.6666666666666665] | |
[0 -7 -2.3333333333333335] | |
[0 -6 -2] | |
...], | |
:via | |
[:irresponsible.babylonians/ribbon-opts | |
:irresponsible.babylonians/paths | |
:irresponsible.babylonians/path], | |
:in [:paths 0]} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment