diff --git a/json/cheshire/clj_easy/tools/json/v0.clj b/json/cheshire/clj_easy/tools/json/v0.clj index 42e1379..d948dfc 100644 --- a/json/cheshire/clj_easy/tools/json/v0.clj +++ b/json/cheshire/clj_easy/tools/json/v0.clj @@ -1,9 +1,13 @@ (ns clj-easy.tools.json.v0 - (:require [cheshire.core :as cheshire])) + (:require [cheshire.core :as cheshire]) + (:import (com.fasterxml.jackson.core.io JsonEOFException))) (defn read-str ([s] (read-str s nil)) - ([s {:keys [key-fn]}] (cheshire/parse-string s (or key-fn keyword)))) + ([s {:keys [key-fn]}] + (try (cheshire/parse-string s (or key-fn keyword)) + (catch JsonEOFException e + (throw (ex-info "Incomplete input" {} e)))))) (defn write-str ([s] (write-str s nil)) diff --git a/json/data-json/clj_easy/tools/json/v0.clj b/json/data-json/clj_easy/tools/json/v0.clj index ae08da2..ae6f090 100644 --- a/json/data-json/clj_easy/tools/json/v0.clj +++ b/json/data-json/clj_easy/tools/json/v0.clj @@ -3,8 +3,11 @@ (defn read-str ([s] (read-str s nil)) - ([s {:keys [key-fn]}] (json/read-str s :key-fn (or key-fn keyword)))) - + ([s {:keys [key-fn]}] + (try (json/read-str s :key-fn (or key-fn keyword)) + (catch Exception e + (throw (ex-info "Incomplete input" {} e)))))) + (defn write-str ([s] (write-str s nil)) ([s _opts] (json/write-str s))) diff --git a/test/clj_easy/tools/json_test.clj b/test/clj_easy/tools/json_test.clj index f69ceea..4b91221 100644 --- a/test/clj_easy/tools/json_test.clj +++ b/test/clj_easy/tools/json_test.clj @@ -7,7 +7,10 @@ (is (= [1 2 3] (json/read-str "[1, 2, 3]"))) (is (= {:a 1} (json/read-str "{\"a\": 1}"))) (is (= {:a 1} (json/read-str "{\"a\": 1}" {:key-fn keyword}))) - (is (= {"a" 1} (json/read-str "{\"a\": 1}" {:key-fn str})))) + (is (= {"a" 1} (json/read-str "{\"a\": 1}" {:key-fn str}))) + (is (thrown-with-msg? clojure.lang.ExceptionInfo + #"Incomplete input" + (json/read-str "{\"a\": 1" {:key-fn str})))) (testing "write json" (is (= [1 2 3] (json/read-str (json/write-str [1 2 3])))) (is (= {:a 1} (json/read-str (json/write-str {:a 1}))))))