anmonteiro / lumo

Fast, cross-platform, standalone ClojureScript environment
Eclipse Public License 1.0
1.88k stars 84 forks source link

Be able to treat warnings as errors #256

Open metametadata opened 7 years ago

metametadata commented 7 years ago

Lumo should support treating warnings as errors. E.g. after passing an additional flag to the executable.

Motivation: to have more reliable scripts. Currently it's too easy to miss an unexpected behaviour on script execution.

Example:

ᐅ lumo -e '(do (+ 1 2 foo) 456)'
                       ⬆
WARNING: Use of undeclared Var cljs.user/foo at line 1 
456
ᐅ echo $?
0

Actual: Expression 456 is reached. Exit code is 0.

Expected: Lumo exits on warning, 456 is not reached. Exit code is 1.

I tried to manually catch cljs.analyzer warnings inside my scripts but with no luck.

mfikes commented 7 years ago

Perhaps generalizing a bit, it should arguably be possible for users to bind their own warning handler function. Currently, the code is structured to set the warning handler that causes the error indicator to be used. https://github.com/anmonteiro/lumo/blob/09c9d125392a687e3dab7a394485caf73cee6752/src/cljs/snapshot/lumo/repl.cljs#L1061

(I'm wondering if a strategy of first checking to see if the default warning handlers set up by ClojureScript are still in place, and assuming if not, that user-level code has replaced them and that they shoudn't be further modified, would work out. I haven't wrapped my mind around whether this is possible to do, though, given that these are analyzer warnings. Hmm.)