l3nz / cli-matic

Compact, hands-free [sub]command line parsing library for Clojure.
Eclipse Public License 2.0
365 stars 29 forks source link

Return value from `(doall ...)` causes `getReturnValue` to throw #142

Open lgessler opened 2 years ago

lgessler commented 2 years ago

version: 0.4.3

platform: JVM 14

problem: Subcommands which return a LazySeq seem to crash because the LazySeq is treated as a deferred value by getReturnValue, and P/waitForDeferredValue attempts to deref the LazySeq, causing the crash.

clojure.lang.LazySeq cannot be cast to java.util.concurrent.Future ...
** ERROR: **
Exception: #error {
 :cause clojure.lang.LazySeq cannot be cast to java.util.concurrent.Future
 :via
 [{:type java.lang.ClassCastException
   :message clojure.lang.LazySeq cannot be cast to java.util.concurrent.Future
   :at [clojure.core$deref_future invokeStatic core.clj 2302]}]
 :trace
 [[clojure.core$deref_future invokeStatic core.clj 2302]
  [clojure.core$deref invokeStatic core.clj 2324]
  [clojure.core$deref invoke core.clj 2310]
  [cli_matic.platform$waitForDeferredValue invokeStatic platform.clj 105]
  [cli_matic.platform$waitForDeferredValue invoke platform.clj 91]
  [cli_matic.core$getReturnValue invokeStatic core.cljc 519]
  [cli_matic.core$getReturnValue invoke core.cljc 506]
  [cli_matic.core$invoke_subcmd invokeStatic core.cljc 547]
  [cli_matic.core$invoke_subcmd invoke core.cljc 525]
  [cli_matic.core$run_cmd_STAR_ invokeStatic core.cljc 589]
  [cli_matic.core$run_cmd_STAR_ invoke core.cljc 560]
  [conllu_rest.core$run_cmd invokeStatic core.clj 90]
  [conllu_rest.core$run_cmd invoke core.clj 86]
  [conllu_rest.core$start_app invokeStatic core.clj 112]
  [conllu_rest.core$start_app invoke core.clj 111]
  [conllu_rest.core$_main invokeStatic core.clj 115]
  [conllu_rest.core$_main doInvoke core.clj 114]
  [clojure.lang.RestFn applyTo RestFn.java 137]
  [conllu_rest.core main nil -1]]}

repro:

See these two files--note that in the former I am returning an :ok to work around this issue. If you remove the :ok from ingest-conllu-files and then make the call to ingest-conllu-files the last form inside ingest, the issue is triggered as the subcommand will then return the result of (doall (pmap ...))

expected behavior:

It seems like getReturnValue should never throw, so this is an unexpected behavior to me. The final form of my code ended up not needing this to work correctly anyway, since I finish the subcommand with some print statements, but I thought I'd mention this regardless.