|
1 | 1 | (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]] |
3 | 4 | [compojure.api.middleware :as mw]
|
4 | 5 | [compojure.api.routes :as routes]
|
5 | 6 | [plumbing.core :as p]
|
|
899 | 900 |
|
900 | 901 | static? (not (or (-> info :public :dynamic)
|
901 | 902 | (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))) |
903 | 909 |
|
904 | 910 | _ (when context?
|
905 | 911 | (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 "}")] |
909 | 924 | (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}))))))) |
916 | 931 |
|
917 | 932 | ;; :dynamic by default
|
918 |
| - static-context? (and static? context? safely-static) |
| 933 | + static-context? (and static? context? (boolean safely-static)) |
919 | 934 |
|
920 | 935 | info (cond-> info
|
921 | 936 | static-context? (assoc :static-context? static-context?))
|
|
0 commit comments