candid82 / joker

Small Clojure interpreter, linter and formatter.
https://joker-lang.org/
Eclipse Public License 1.0
1.64k stars 67 forks source link

Exceptions from :parse-fn w/ joker.tools.cli are not caught #470

Closed hlship closed 2 years ago

hlship commented 3 years ago

Calls to the parse-fn option are supposed to be wrapped such that exceptions are promotted into parse errors; that either isn't happening, or the strack trace of the thrown exception is becoming the error message.

Welcome to joker v0.17.2. Use '(exit)', EOF (Ctrl-D), or SIGINT (Ctrl-C) to exit.
user=> (require '[joker.tools.cli :as cli])
nil
user=> (cli/parse-opts ["-P" "3.2"] [["-P" "--para N" :parse-fn joker.strconv/atoi]])
{:options {}, :arguments [], :summary "  -P, --para N", :errors ["Error while parsing option \"-P 3.2\": <joker.tools.cli>:228:28: Eval error: strconv.Atoi: parsing \"3.2\": invalid syntax\nStacktrace:\n  global <repl>:3:1\n  joker.tools.cli/parse-opts <joker.tools.cli>:545:23\n  joker.tools.cli/parse-option-tokens <joker.tools.cli>:271:9\n  core/reduce <joker.core>:702:17\n  f <joker.tools.cli>:274:35\n  joker.tools.cli/parse-optarg <joker.tools.cli>:248:9\n  joker.tools.cli/parse-value <joker.tools.cli>:228:28"]}
hlship commented 3 years ago

Note that:

user=> (require '[joker.strconv :refer [atoi]])
nil
user=> (atoi "3.2")
<repl>:7:1: Eval error: strconv.Atoi: parsing "3.2": invalid syntax
user=> (try (atoi "3.2") (catch Error e (prn (ex-message e))))
"strconv.Atoi: parsing \"3.2\": invalid syntax"
nil
hlship commented 3 years ago

I'll work on a PR for this.