From 36ae914e6e07c1472a5f1529d2c72e49da23a10e Mon Sep 17 00:00:00 2001 From: lucacervello Date: Sat, 12 Aug 2017 10:43:54 +0200 Subject: [PATCH] changed exception type and message --- src/cheshire/exact.clj | 4 +++- test/cheshire/test/core.clj | 25 +++++++++++++------------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/cheshire/exact.clj b/src/cheshire/exact.clj index 00a5b605..c582e502 100644 --- a/src/cheshire/exact.clj +++ b/src/cheshire/exact.clj @@ -11,7 +11,9 @@ (catch Exception _ false))] (if valid-json? parsed - (throw (Exception. "Invalid json"))))) + (throw + (IllegalArgumentException. + "Invalid JSON, expected exactly one parseable object but multiple objects were found"))))) (defn parse-string "Like cheshire.core/parse-string diff --git a/test/cheshire/test/core.clj b/test/cheshire/test/core.clj index a258d482..527ce664 100644 --- a/test/cheshire/test/core.clj +++ b/test/cheshire/test/core.clj @@ -399,15 +399,16 @@ (is (= {:a 1} (json/decode "{\"a\": 1}" (Boolean. true))))) (deftest t-invalid-json - (are [x y] (= x (try - y - (catch Exception e - (.getMessage e)))) - "Invalid json" (json-exact/decode "{\"foo\": 1}asdf") - "Invalid json" (json-exact/decode "{\"foo\": 123}null") - "Invalid json" (json-exact/decode "\"hello\" : 123}") - {"foo" 1} (json/decode "{\"foo\": 1}") - "Invalid json" (json-exact/decode-strict "{\"foo\": 1}asdf") - "Invalid json" (json-exact/decode-strict "{\"foo\": 123}null") - "Invalid json" (json-exact/decode-strict "\"hello\" : 123}") - {"foo" 1} (json/decode-strict "{\"foo\": 1}"))) + (let [invalid-json-message "Invalid JSON, expected exactly one parseable object but multiple objects were found"] + (are [x y] (= x (try + y + (catch Exception e + (.getMessage e)))) + invalid-json-message (json-exact/decode "{\"foo\": 1}asdf") + invalid-json-message (json-exact/decode "{\"foo\": 123}null") + invalid-json-message (json-exact/decode "\"hello\" : 123}") + {"foo" 1} (json/decode "{\"foo\": 1}") + invalid-json-message (json-exact/decode-strict "{\"foo\": 1}asdf") + invalid-json-message (json-exact/decode-strict "{\"foo\": 123}null") + invalid-json-message (json-exact/decode-strict "\"hello\" : 123}") + {"foo" 1} (json/decode-strict "{\"foo\": 1}"))))