More "error" use instead of "warn"

This commit is contained in:
mike-thompson-day8 2015-05-02 10:49:27 +10:00
parent 7ebfc2a9ba
commit b921fa497d
2 changed files with 10 additions and 7 deletions

View File

@ -1,6 +1,6 @@
(ns re-frame.handlers
(:require [re-frame.db :refer [app-db]]
[re-frame.utils :refer [first-in-vector warn]]))
[re-frame.utils :refer [first-in-vector warn error]]))
;; -- composing middleware -----------------------------------------------------------------------
@ -73,9 +73,9 @@
(let [event-id (first-in-vector event-v)
handler-fn (lookup-handler event-id)]
(if (nil? handler-fn)
(warn "re-frame: no event handler registered for: \"" event-id "\". Ignoring.") ;; TODO: make exception
(error "re-frame: no event handler registered for: \"" event-id "\". Ignoring.")
(if *handling*
(warn "re-frame: in the middle of handling \"" *handling* "\" tried to handle \"" event-v "\"")
(error "re-frame: while handling \"" *handling* "\" dispatch-sync was called for \"" event-v "\". You can't call dispatch-sync in an event handler.")
(binding [*handling* event-v]
(handler-fn app-db event-v))))))

View File

@ -2,7 +2,7 @@
(:require
[reagent.ratom :refer [IReactiveAtom]]
[re-frame.undo :refer [store-now!]]
[re-frame.utils :refer [warn log group groupEnd]]
[re-frame.utils :refer [warn log group groupEnd error]]
[clojure.data :as data]))
@ -31,7 +31,7 @@
(let [db @app-db
new-db (handler db event-vec)]
(if (nil? new-db)
(warn "re-frame: your pure handler returned nil. It should return the new db state.")
(error "re-frame: your pure handler returned nil. It should return the new db state.")
(if-not (identical? db new-db)
(reset! app-db new-db)))))))
@ -48,6 +48,7 @@
[handler]
(fn log-ex-handler
[db v]
(warn "re-frame: use of \"log-ex\" is deprecated. You don't need it any more. Chrome seems to now produce good stack traces.")
(try
(handler db v)
(catch :default e ;; ooops, handler threw
@ -101,7 +102,9 @@
[& args]
(let [path (flatten args)
_ (if (empty? path)
(warn "re-frame: \"path\" middleware given no params. Probably a mistake."))]
(error "re-frame: \"path\" middleware given no params."))
_ (if (fn? (first args))
(error "re-frame: you've used \"path\" incorrectly. It is a middleare factory and must be called like this \"(path something)\", whereas you just supplied \"path\"."))]
(fn path-middleware
[handler]
(fn path-handler
@ -124,7 +127,7 @@
(fn? explanation) (explanation db event-vec)
(string? explanation) explanation
(nil? explanation) ""
:else (warn "re-frame: \"undoable\" middleware given a bad parameter. Got: " explanation))]
:else (error "re-frame: \"undoable\" middleware given a bad parameter. Got: " explanation))]
(store-now! explanation)
(handler db event-vec)))))