From a75b7e74209193cc383cdcd2dcd01d94aead4722 Mon Sep 17 00:00:00 2001 From: Stuart Halloway Date: Thu, 1 Nov 2012 09:57:48 -0400 Subject: [PATCH] better error message when passing non-seqs to (seq) --- src/jvm/clojure/lang/RT.java | 3 +- test/clojure/test_clojure/data_structures.clj | 2 +- test/clojure/test_clojure/sequences.clj | 42 ++++++++++++------------ 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/jvm/clojure/lang/RT.java b/src/jvm/clojure/lang/RT.java index e854c11..c06d4ae 100644 --- a/src/jvm/clojure/lang/RT.java +++ b/src/jvm/clojure/lang/RT.java @@ -492,7 +492,8 @@ static ISeq seqFrom(Object coll){ else { Class c = coll.getClass(); Class sc = c.getSuperclass(); - throw new IllegalArgumentException("Don't know how to create ISeq from: " + c.getName()); + throw new ExceptionInfo("Don't know how to create ISeq from: " + c.getName(), + map(Keyword.intern("instance"), coll)); } } diff --git a/test/clojure/test_clojure/data_structures.clj b/test/clojure/test_clojure/data_structures.clj index 3d913b3..7e6d0b5 100644 --- a/test/clojure/test_clojure/data_structures.clj +++ b/test/clojure/test_clojure/data_structures.clj @@ -557,7 +557,7 @@ (deftest test-get (let [m {:a 1, :b 2, :c {:d 3, :e 4}, :f nil, :g false, nil {:h 5}}] - (is (thrown? IllegalArgumentException (get-in {:a 1} 5))) + (is (thrown? Throwable (get-in {:a 1} 5))) (are [x y] (= x y) (get m :a) 1 (get m :e) nil diff --git a/test/clojure/test_clojure/sequences.clj b/test/clojure/test_clojure/sequences.clj index e69fdbb..b9de9f5 100644 --- a/test/clojure/test_clojure/sequences.clj +++ b/test/clojure/test_clojure/sequences.clj @@ -139,7 +139,7 @@ (deftest test-cons - (is (thrown? IllegalArgumentException (cons 1 2))) + (is (thrown? Throwable (cons 1 2))) (are [x y] (= x y) (cons 1 nil) '(1) (cons nil nil) '(nil) @@ -244,13 +244,13 @@ (deftest test-first ;(is (thrown? Exception (first))) - (is (thrown? IllegalArgumentException (first true))) - (is (thrown? IllegalArgumentException (first false))) - (is (thrown? IllegalArgumentException (first 1))) - ;(is (thrown? IllegalArgumentException (first 1 2))) - (is (thrown? IllegalArgumentException (first \a))) - (is (thrown? IllegalArgumentException (first 's))) - (is (thrown? IllegalArgumentException (first :k))) + (is (thrown? Throwable (first true))) + (is (thrown? Throwable (first false))) + (is (thrown? Throwable (first 1))) + ;(is (thrown? Throwable (first 1 2))) + (is (thrown? Throwable (first \a))) + (is (thrown? Throwable (first 's))) + (is (thrown? Throwable (first :k))) (are [x y] (= x y) (first nil) nil @@ -310,14 +310,14 @@ (deftest test-next - ; (is (thrown? IllegalArgumentException (next))) - (is (thrown? IllegalArgumentException (next true))) - (is (thrown? IllegalArgumentException (next false))) - (is (thrown? IllegalArgumentException (next 1))) - ;(is (thrown? IllegalArgumentException (next 1 2))) - (is (thrown? IllegalArgumentException (next \a))) - (is (thrown? IllegalArgumentException (next 's))) - (is (thrown? IllegalArgumentException (next :k))) + ; (is (thrown? Throwable (next))) + (is (thrown? Throwable (next true))) + (is (thrown? Throwable (next false))) + (is (thrown? Throwable (next 1))) + ;(is (thrown? Throwable (next 1 2))) + (is (thrown? Throwable (next \a))) + (is (thrown? Throwable (next 's))) + (is (thrown? Throwable (next :k))) (are [x y] (= x y) (next nil) nil @@ -445,7 +445,7 @@ ;; (ffirst coll) = (first (first coll)) ;; (deftest test-ffirst -; (is (thrown? IllegalArgumentException (ffirst))) +; (is (thrown? Throwable (ffirst))) (are [x y] (= x y) (ffirst nil) nil @@ -465,7 +465,7 @@ ;; (fnext coll) = (first (next coll)) = (second coll) ;; (deftest test-fnext -; (is (thrown? IllegalArgumentException (fnext))) +; (is (thrown? Throwable (fnext))) (are [x y] (= x y) (fnext nil) nil @@ -489,7 +489,7 @@ ;; (nfirst coll) = (next (first coll)) ;; (deftest test-nfirst -; (is (thrown? IllegalArgumentException (nfirst))) +; (is (thrown? Throwable (nfirst))) (are [x y] (= x y) (nfirst nil) nil @@ -509,7 +509,7 @@ ;; (nnext coll) = (next (next coll)) ;; (deftest test-nnext -; (is (thrown? IllegalArgumentException (nnext))) +; (is (thrown? Throwable (nnext))) (are [x y] (= x y) (nnext nil) nil @@ -877,7 +877,7 @@ (deftest test-repeat - ;(is (thrown? IllegalArgumentException (repeat))) + ;(is (thrown? Throwable (repeat))) ; infinite sequence => use take (are [x y] (= x y) -- 1.7.3.5