Skip to content

Commit

Permalink
runtime: silence "Use of undeclared Var ..." warnings by default
Browse files Browse the repository at this point in the history
Introduce :silence-use-of-undeclared-var-warnings pref.
  • Loading branch information
darwin committed May 17, 2016
1 parent a2ed00a commit 222f867
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/runtime/dirac/runtime/prefs.clj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
(def ^:dynamic *context-availablity-next-trial-waiting-time* (env :context-availablity-next-trial-waiting-time))
(def ^:dynamic *eval-time-limit* (env :dirac-eval-time-limit))
(def ^:dynamic *runtime-tag* (or (env :dirac-runtime-tag) (attempt-to-determine-runtime-tag)))
(def ^:dynamic *silence-use-of-undeclared-var-warnings* (env :dirac-silence-use-of-undeclared-var-warnings))

(defmacro static-pref [key kind]
(let [sym (symbol (str "*" (name key) "*"))]
Expand All @@ -65,4 +66,5 @@
(static-pref :context-availablity-total-time-limit :int)
(static-pref :context-availablity-next-trial-waiting-time :int)
(static-pref :eval-time-limit :int)
(static-pref :runtime-tag :str)))
(static-pref :runtime-tag :str)
(static-pref :silence-use-of-undeclared-var-warnings :boolean)))
3 changes: 2 additions & 1 deletion src/runtime/dirac/runtime/prefs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
:context-availablity-next-trial-waiting-time 10
:eval-time-limit 10000
:java-trace-header-style "color:red"
:runtime-tag "unidentified"})
:runtime-tag "unidentified"
:silence-use-of-undeclared-var-warnings true})

(def static-prefs (gen-static-prefs)) ; this config is comming from environment and system properties

Expand Down
21 changes: 19 additions & 2 deletions src/runtime/dirac/runtime/repl.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,23 @@
(log request-id :stderr (remove-common-whitespace-prefix rest-content))
(group-end)))))

(defn should-silence-warning? [message]
(cond
(and (pref :silence-use-of-undeclared-var-warnings) (re-find #"^Use of undeclared Var" message)) true
:else false))

(defn should-silence-error? [_message]
(cond
:else false))

(defn emit-warning! [request-id message]
(when-not (should-silence-warning? message)
(warn request-id "warning" message)))

(defn emit-error! [request-id message]
(when-not (should-silence-error? message)
(error request-id "error" message)))

; -- REPL API ---------------------------------------------------------------------------------------------------------------

(def api-version 3) ; version of REPL API
Expand All @@ -116,9 +133,9 @@
(case kind
"java-trace" (present-java-trace request-id text)
(if-let [warning-msg (detect-and-strip "WARNING:" text)]
(warn request-id "warning" warning-msg)
(emit-warning! request-id warning-msg)
(if-let [error-msg (detect-and-strip "ERROR:" text)]
(error request-id "error" error-msg)
(emit-error! request-id error-msg)
(log request-id kind text)))))

(defn ^:export postprocess-successful-eval
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
(auto/console-exec-and-wait-for-match! "(range 200)" "log> (0 1 2 3 4 …)")
(auto/console-exec-and-wait-for-match! "(doc filter)" "log> null")
(auto/console-exec-and-wait-for-match! "js/dirac" (str "log> " dirac-object))
(auto/console-exec-and-wait-for-match! "(x)" ["wrn> Use of undeclared Var cljs.user/x at line 1 <dirac repl>"
"err> TypeError: Cannot read property 'call' of undefined(…)"])
(auto/console-exec-and-wait-for-match! "(x)" "err> TypeError: Cannot read property 'call' of undefined(…)")
(auto/console-exec-and-wait-for-match! "(in-ns)" [(str "log> java.lang.IllegalArgumentException: "
"Argument to in-ns must be a symbol.")
"<elided stack trace log>"
Expand Down
1 change: 0 additions & 1 deletion test/browser/transcripts/expected/suite01-dirac-eval.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ automate #1 {:action :dispatch-console-prompt-action, :input "enter"}
devtools #1 DC.log> (x)
devtools #1 send-eval-request: (x)
devtools #1 present-server-side-output! stderr > WARNING: Use of undeclared Var cljs.user/x at line 1 <dirac repl>
devtools #1 DF.wrn> Use of undeclared Var cljs.user/x at line 1 <dirac repl>
devtools #1 wrap-with-postprocess-and-eval-in-current-context!
devtools #1 DF.err> TypeError: Cannot read property 'call' of undefined(…)
automate #1 {:action :dispatch-console-prompt-input, :input "(in-ns)"}
Expand Down

0 comments on commit 222f867

Please sign in to comment.