Skip to content

Some IllegalArgumentException messages in error_dictionary.clj incorrectly assume that a sequence was passed #69

@stanislowskij

Description

@stanislowskij

Certain functions that expect an integer argument and are not spec'd by Babel get caught by the :illegal-arg-must-be-int-seq error in our error_dictionary.clj. The message for this is misleading in cases where a sequence is not passed.

To reproduce/test:

  1. Since (even?) and (odd?) are currently underspec'd, passing a double to them instead of an int will produce these errors:
babel.middleware=> (odd? 2.4)
Expected an integer number, but a sequence 2.4 was given instead.
  1. Entirely removing the spec for these functions also produces the same error for any non-integer argument.

Using a spec'd predicate in a higher-level spec seemingly "bypasses" the specs on the predicate function due to being evaluated differently from user code. This is also an unavoidable case, i.e. a cause for why these messages need to be improved even if the specs are fixed:

In corefns.clj:

(s/fdef clojure.core/even?
  :args :babel.args/one-number)
(stest/instrument `clojure.core/even?)
(defn x [n] n)
(s/fdef x :args (s/cat :number even?))
(stest/instrument `x)
babel.middleware=> (corefns.corefns/x :a)
Expected an integer number, but a sequence :a was given instead.

TODO: Find examples of the other one:

{:key :illegal-arg-must-be-int-lazy
    :class "IllegalArgumentException"
    :match (beginandend #"Argument must be an integer: clojure\.lang\.LazySeq(.*)")
    :fn (fn [matches] (str "Expected an integer number, but a sequence was given instead.\n"))}

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinggood first issueGood for newcomersneeds explorationNeed to find more specific examples and narrow down the issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions