Planck essentially takes advantage of this to print warning messages in a
different color, so it definitely:
cljs.user=> (+ n 5)
WARNING: Use of undeclared Var cljs.user/n at line 1
NaN
So, yeah, that works. The problem is that you might have other things going out
the err stream.
cljs.user=> (binding [*print-fn* *print-err-fn*]
#_=> (println "Danger, Will Robinson!"))
Danger, Will Robinson!
nil
Hooking into the custom warning handler machinery via *cljs-warning-handlers*
might be a cleaner route, if you need finer-grained control of things. (I’m
presuming this mechanism would work in self-host, but I’ve never tried it.)
(Jake McCrary has a good exposition on the subject:
http://jakemccrary.com/blog/2015/12/19/clojurescript-treat-warnings-as-errors/).
- Mike
> On Apr 12, 2016, at 9:41 PM, J David Eisenberg <[email protected]>
> wrote:
>
> If I evaluate this expression without defining a variable n:
>
> (+ n 5)
>
> I get this in my console.log:
>
> WARNING: Use of undeclared Var cljs.user/n at line 1
>
> and the result is NaN.
>
> I would like to capture the warning message so I can show it to the end user.
> When I take out (enable-console-print!) I get this message:
>
> Error: No *print-err-fn* fn set for evaluation environment
>
> so I presume I should be able to put in my own *print-err-fn* to intercept
> the warning message. Am I on the right track?
>
> --
> Note that posts from new members are moderated - please be patient with your
> first post.
> ---
> You received this message because you are subscribed to the Google Groups
> "ClojureScript" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/clojurescript.
--
Note that posts from new members are moderated - please be patient with your
first post.
---
You received this message because you are subscribed to the Google Groups
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/clojurescript.