From 8e2e0c07f6f95d74dca3d1bcbc15a43140a9e7e4 Mon Sep 17 00:00:00 2001 From: Tommi Reiman Date: Mon, 18 Sep 2017 08:29:52 +0300 Subject: [PATCH] Polish errors --- src/reitit/core.cljc | 13 ++++++++----- src/reitit/impl.cljc | 2 +- src/reitit/spec.cljc | 4 ++-- test/cljc/reitit/core_test.cljc | 4 ++-- test/cljc/reitit/spec_test.cljc | 2 +- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/reitit/core.cljc b/src/reitit/core.cljc index faf0e60f..ec6d0542 100644 --- a/src/reitit/core.cljc +++ b/src/reitit/core.cljc @@ -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] diff --git a/src/reitit/impl.cljc b/src/reitit/impl.cljc index be1e610c..9d81dfee 100644 --- a/src/reitit/impl.cljc +++ b/src/reitit/impl.cljc @@ -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 diff --git a/src/reitit/spec.cljc b/src/reitit/spec.cljc index 32e956ff..b5457e42 100644 --- a/src/reitit/spec.cljc +++ b/src/reitit/spec.cljc @@ -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 diff --git a/test/cljc/reitit/core_test.cljc b/test/cljc/reitit/core_test.cljc index 0540d68c..e30be346 100644 --- a/test/cljc/reitit/core_test.cljc +++ b/test/cljc/reitit/core_test.cljc @@ -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" diff --git a/test/cljc/reitit/spec_test.cljc b/test/cljc/reitit/spec_test.cljc index fd3334cb..c0fd21f5 100644 --- a/test/cljc/reitit/spec_test.cljc +++ b/test/cljc/reitit/spec_test.cljc @@ -67,7 +67,7 @@ (reitit/router ["/api"] opts))) - {:path ""} + {:path "api"} {:path nil} {:meta nil} {:expand nil}