Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
hlship opened this issue Sep 9, 2021 · 2 comments
Closed

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

hlship opened this issue Sep 9, 2021 · 2 comments

Comments

@hlship
Copy link
Contributor

hlship commented Sep 9, 2021

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
Copy link
Contributor Author

hlship commented Sep 9, 2021

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
Copy link
Contributor Author

hlship commented Sep 9, 2021

I'll work on a PR for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant