spec.cljs 890 B

12345678910111213141516171819202122232425262728
  1. (ns frontend.spec
  2. (:require [cljs.spec.alpha :as s]
  3. [frontend.config :as config]
  4. [lambdaisland.glogi :as log]
  5. [expound.alpha :as expound]))
  6. ;; Enabled for all environments. We want asserts to run in production e.g.
  7. ;; frontend.storage one is preventing data corruption. If we introduce asserts
  8. ;; that are not perf sensitive, we will need to reconsider.
  9. (s/check-asserts true)
  10. (set! s/*explain-out* expound/printer)
  11. (defn validate
  12. "This function won't crash the current thread, just log error."
  13. [spec value]
  14. (when config/dev?
  15. (if (s/explain-data spec value)
  16. (let [error-message (expound/expound-str spec value)
  17. ex (ex-info "Error in validate" {:value value})]
  18. (log/error :exception ex :spec/validate-failed error-message)
  19. false)
  20. true)))
  21. ;; repo
  22. (s/def :repos/url string?)
  23. (s/def :repos/branch string?)