Skip to content

Commit 7f9e835

Browse files
committed
coach
1 parent b5ceef3 commit 7f9e835

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

src/compojure/api/meta.clj

+27-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
(ns compojure.api.meta
2-
(:require [compojure.api.common :refer [extract-parameters]]
2+
(:require [clojure.edn :as edn]
3+
[compojure.api.common :refer [extract-parameters]]
34
[compojure.api.middleware :as mw]
45
[compojure.api.routes :as routes]
56
[plumbing.core :as p]
@@ -899,23 +900,37 @@
899900

900901
static? (not (or (-> info :public :dynamic)
901902
(route-args? route-arg) (seq lets) (seq letks)))
902-
safely-static (or (-> info :public :static) (static-body? &env body))
903+
safely-static (or (-> info :public :static)
904+
(try (static-body? &env body)
905+
(catch Exception e
906+
(println `restructure-param "Internal error, please report the following trace to https://github.com/metosin/compojure-api")
907+
(prn e)
908+
false)))
903909

904910
_ (when context?
905911
(when-not safely-static
906-
(when-some [coach (or (System/getProperty "compojure.api.meta.static-context-coach")
907-
"assert")]
908-
(when (and static? (not (-> info :public :static)))
912+
(when (and static? (not (-> info :public :static)))
913+
(let [coach (or (some-> (System/getProperty "compojure.api.meta.static-context-coach")
914+
edn/read-string)
915+
{:default :print})
916+
nsym (ns-name *ns*)
917+
mode (or (get coach nsym)
918+
(get coach :default)
919+
:print)
920+
msg (str "This looks like it could be a static context: " (pr-str {:form &form :meta (meta &form)})
921+
"\n\n"
922+
"To suppress this message for this namespace use -Dcompojure.api.meta.static-context-coach="
923+
"{" nsym :off "}")]
909924
(case coach
910-
"off" nil
911-
"print" (println "This looks like it could be a static context: " (pr-str {:form &form :meta (meta &form)}))
912-
"assert" (throw (ex-info "This looks like it could be a static context"
913-
{:form &form
914-
:meta (meta &form)}))
915-
(throw (ex-info "compojure.api.meta.static-context-coach must be either print or assert" {:provided coach})))))))
925+
:off nil
926+
:print (println msg)
927+
:assert (throw (ex-info msg
928+
{:form &form
929+
:meta (meta &form)}))
930+
(throw (ex-info "compojure.api.meta.static-context-coach must be either :off, :print, or :assert" {:provided coach})))))))
916931

917932
;; :dynamic by default
918-
static-context? (and static? context? safely-static)
933+
static-context? (and static? context? (boolean safely-static))
919934

920935
info (cond-> info
921936
static-context? (assoc :static-context? static-context?))

0 commit comments

Comments
 (0)