Skip to content

Gracefully handle unexpected syntax #36

@vemv

Description

@vemv

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions