Polish errors

This commit is contained in:
Tommi Reiman 2017-09-18 08:29:52 +03:00
parent aff2229151
commit 8e2e0c07f6
5 changed files with 14 additions and 11 deletions

View file

@ -73,14 +73,17 @@
(seq)
(into {})))
(defn conflicts-str [conflicts]
(apply str "Router contains conflicting routes:\n\n"
(mapv
(fn [[[path] vals]]
(str " " path "\n-> " (str/join "\n-> " (mapv first vals)) "\n\n"))
conflicts)))
(defn throw-on-conflicts! [conflicts]
(throw
(ex-info
(apply str "router contains conflicting routes:\n\n"
(mapv
(fn [[[path] vals]]
(str " " path "\n-> " (str/join "\n-> " (mapv first vals)) "\n\n"))
conflicts))
(conflicts-str conflicts)
{:conflicts conflicts})))
(defn name-lookup [[_ {:keys [name]}] opts]

View file

@ -155,7 +155,7 @@
missing (clojure.set/difference required defined)]
(throw
(ex-info
(str "missing path-params for route " template ": " missing)
(str "missing path-params for route " template " -> " missing)
{:params params, :required required})))))
(defn fast-assoc

View file

@ -8,7 +8,7 @@
;; routes
;;
(s/def ::path (s/with-gen (s/and string? #(str/starts-with? % "/"))
(s/def ::path (s/with-gen (s/and string? #(or (str/blank? %) (str/starts-with? % "/")))
#(gen/fmap (fn [s] (str "/" s)) (s/gen string?))))
(s/def ::arg (s/and any? (complement vector?)))
@ -18,7 +18,7 @@
(s/def ::raw-route
(s/cat :path ::path
:arg (s/? ::arg)
:childs (s/* (s/and ::raw-route))))
:childs (s/* (s/and (s/nilable ::raw-route)))))
(s/def ::raw-routes
(s/or :route ::raw-route

View file

@ -38,7 +38,7 @@
(is (= true (reitit/partial-match? (reitit/match-by-name router ::beer))))
(is (thrown-with-msg?
ExceptionInfo
#"^missing path-params for route /api/ipa/:size: \#\{:size\}$"
#"^missing path-params for route /api/ipa/:size -> \#\{:size\}$"
(reitit/match-by-name! router ::beer))))))
(testing "lookup-router"
@ -197,7 +197,7 @@
(testing "throws by default"
(is (thrown-with-msg?
ExceptionInfo
#"router contains conflicting routes"
#"Router contains conflicting routes"
(reitit/router
[["/a"] ["/a"]]))))
(testing "can be configured to ignore"

View file

@ -67,7 +67,7 @@
(reitit/router
["/api"] opts)))
{:path ""}
{:path "api"}
{:path nil}
{:meta nil}
{:expand nil}