Welcome! Please see the About page for a little more info on how this works.

+1 vote
in Errors by
closed by

The error message generated when case encounters a non-matching clause uses str, resulting in nil being rendered as an empty string, and strings without quote marks.

For example:

(let [x nil]
  (case x
    1 :a 2 :b))
;; =>
;; Unhandled java.lang.IllegalArgumentException
;; No matching clause for x:

And the potentially confusing

(let [x "1"]
  (case x
    1 :a 2 :b))
;; =>
;; Unhandled java.lang.IllegalArgumentException
;; No matching clause for x: 1

Would it be less ambiguous to use pr-str for the value resulting in nil and "1" respectively?

Note: a similar issue was raised for Clojurescript here:
https://ask.clojure.org/index.php/6575/improve-error-messages-using-instead-when-printing-objects

Logged: https://clojure.atlassian.net/browse/CLJ-2564

closed with the note: Released

2 Answers

0 votes
by
 
Best answer

Fixed in 1.10.2-alpha2

+3 votes
by

Makes sense, logged.

by
Thanks! Grepping through the clojure.core source I found a few other similar places where pr-str could be used, here are example cases:

(case nil
  nil 1 nil 2)

(even? "10")

(requiring-resolve nil)

(condp = nil)
...