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

Gracefully handle unexpected syntax #36

Open
vemv opened this issue Dec 28, 2018 · 1 comment
Open

Gracefully handle unexpected syntax #36

vemv opened this issue Dec 28, 2018 · 1 comment

Comments

@vemv
Copy link

vemv commented Dec 28, 2018

Brief

defn-spec could be a superset of defn, but it isn't, and also not in a very informative manner:

orchestra.expound-test=> (defn-spec foo [])

IllegalArgumentException find not supported on type: clojure.lang.Keyword  clojure.lang.RT.find (RT.java:863)
orchestra.expound-test=> (defn-spec foo [a])

IllegalArgumentException find not supported on type: clojure.lang.Keyword  clojure.lang.RT.find (RT.java:863)
orchestra.expound-test=> (defn-spec foo [a any?])

IllegalArgumentException find not supported on type: clojure.lang.Keyword  clojure.lang.RT.find (RT.java:863)
orchestra.expound-test=> (defn-spec foo any? [a any?])
orchestra.expound-test/foo

IOW, find not supported on type: clojure.lang.Keyword is not the best message one can find when writing a defn-spec using "muscle memory" from defn.

Fix

I'd suggest at least one of the following:

  • If specs are omitted, they are assumed to be any?, possibly emitting a warning. All of this could be configurable behavior.
  • Specs are required, otherwise the situation is precisely detected and informed of, in plain English:
    • No :ret spec supplied. Did you forget to add a spec after the function name?
    • No :args spec supplied for the last parameter. Did you forget to add a spec after the last parameter?

WDYT?

Cheers - Victor

@vemv
Copy link
Author

vemv commented Dec 28, 2018

As a random thought, defn-spec being a superset of defn would open some interesting doors.

One could refactor codebases to bulk-rename defn to defn-spec, resulting in a more homogeneous codebase (seeing interspersed defn/defn-spec calls is ugly), and inviting one to spec more stuff (assuming a warning approach as outlined above).

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