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

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

Open
stanislowskij opened this issue Sep 17, 2024 · 0 comments
Assignees
Labels
bug Something isn't working good first issue Good for newcomers needs exploration Need to find more specific examples and narrow down the issue

Comments

@stanislowskij
Copy link
Collaborator

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"))}
@stanislowskij stanislowskij added bug Something isn't working good first issue Good for newcomers labels Sep 17, 2024
@stanislowskij stanislowskij added the needs exploration Need to find more specific examples and narrow down the issue label Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers needs exploration Need to find more specific examples and narrow down the issue
Projects
None yet
Development

No branches or pull requests

2 participants