I'm adapting cli-matic to work with nodejs using the Clojure CLI tools.
problem
When I pass an unknown subcommand I get a crash involving a Java Throwable
repro
I don't have an example yet, maybe later this week. I'm still testing the code.
expected behavior
Catch the error and emit a message as designed. With my fix I get a stacktrace with
message: 'Unknown subcommand: foobar - in path ["obazl" "foobar"]',
... some more stuff
actual behavior
/Users/gar/bazel/obazl/tool/out/cli_matic/utils_v2.js:116
}catch (e1580){if((e1580 instanceof java.lang.Throwable)){
^
ReferenceError: java is not defined
... stack trace ...
analysis
The current code won't work because (I think) it tries to use a reader conditional to deal with cljs macro definition. The code (in platform_macros.cljc) looks like this, schematically:
#?(:clj (defmacro foo ...definition using java stuff ...))
#?(:cljs (defmacro foo ...definition using only cljs-friendly stuff...))
I believe the problem is that platform_macros.cljc will be processed in clj mode for the macros, so the :clj version ends up being used.
solution
Here's an alternative that seems to work:
macros_cljs.cljc: (defmacro foo ... definition, in clj, for cljs version ...)macros_clj.cljc: (defmacro foo ...definition, in clj, using java stuff ...)
So macros_cljs.cljc contains a clj definition for the macro that works for cljs. The file must be .cljc because it is processed twice, once as clj for the macro and once as cljs. At least I think that's how it works, based on trial and error. Note that there are no reader conditionals in the macro definition files - there would be no point, since such macros are always :clj.
version
Commit 3e072260e359be51bf6646e219042c319dd9f5f8
platform
I'm adapting cli-matic to work with nodejs using the Clojure CLI tools.
problem
When I pass an unknown subcommand I get a crash involving a Java Throwable
repro
I don't have an example yet, maybe later this week. I'm still testing the code.
expected behavior
Catch the error and emit a message as designed. With my fix I get a stacktrace with
actual behavior
analysis
The current code won't work because (I think) it tries to use a reader conditional to deal with cljs macro definition. The code (in
platform_macros.cljc
) looks like this, schematically:and usage is:
I believe the problem is that
platform_macros.cljc
will be processed in clj mode for the macros, so the :clj version ends up being used.solution
Here's an alternative that seems to work:
macros_cljs.cljc
:(defmacro foo ... definition, in clj, for cljs version ...)
macros_clj.cljc
:(defmacro foo ...definition, in clj, using java stuff ...)
Usage:
So
macros_cljs.cljc
contains a clj definition for the macro that works for cljs. The file must be .cljc because it is processed twice, once as clj for the macro and once as cljs. At least I think that's how it works, based on trial and error. Note that there are no reader conditionals in the macro definition files - there would be no point, since such macros are always :clj.