Skip to content

Instantly share code, notes, and snippets.

@semperos
Last active March 31, 2016 16:39
Show Gist options
  • Select an option

  • Save semperos/98c7d0af9ee3ab9708bb7dc2ff127208 to your computer and use it in GitHub Desktop.

Select an option

Save semperos/98c7d0af9ee3ab9708bb7dc2ff127208 to your computer and use it in GitHub Desktop.
Clojure core condition system from Chris Houser's talk https://www.youtube.com/watch?v=zp0OEDcAro0
;; === errors ===
(defn ^:dynamic *malformed-log-entry-error* [msg info]
(throw (ex-info msg info)))
;; === restarts ===
(def ^:dynamic *use-value*)
(def ^:dynamic *skip-log-entry*)
(def ^:dynamic *reparse-entry*)
;; Low-level function
(defn parse-log-entry [text]
(if (well-formed-log-entry? text)
{:successfully-parsed text}
(binding [*use-value* identity
*reparse-entry* parse-log-entry]
(*malformed-log-entry-error*
"Log entry was malformed; could not parse."
{:text text}))))
;; Higher-level function that ends up calling parse-log-entry
(defn log-analyzer []
(binding [*malformed-log-entry-error*
(fn [msg info]
(*use-value*
;; This becomes the parsed log entry in case of error
{:failed-to-parse (:text info)}))]
(doseq [log (find-all-logs)]
(analyze-log log))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment