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

+3 votes
in Errors by
reopened ago 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

2 Answers

0 votes
by
 
Best answer

Fixed in 1.10.2-alpha2

ago by
Given that this was removed from 1.10 (because of the var incompatibility), can this Ask be re-opened and the original patch be reconsidered? Adding the var seems to be an issue, but changing `str` to `pr-str` is minimally invasive while solving the issue at hand.
ago by
Yes, was rolled back in 1.10.3 as it introduced a reliance on a new function so code compiled with 1.10.2 would not run on older runtimes. Reopened this Ask.
+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)
...