[#82] Make it easier to spot new->old Nippy thaw failures

This commit is contained in:
Peter Taoussanis 2016-04-14 00:13:33 +07:00
parent 8fda27e996
commit 3ab91763c6

View file

@ -962,20 +962,21 @@
(def ^:private class-method-sig (into-array Class [IPersistentMap])) (def ^:private class-method-sig (into-array Class [IPersistentMap]))
(defn- read-custom! [in type-id] (defn- read-custom! [in prefixed? type-id]
(if-let [custom-reader (get *custom-readers* type-id)] (if-let [custom-reader (get *custom-readers* type-id)]
(try (try
(custom-reader in) (custom-reader in)
(catch Exception e (catch Exception e
(throw (throw
(ex-info (ex-info
(str "Reader exception for custom type with internal id: " (str "Reader exception for custom type id: " type-id)
type-id) {:internal-type-id type-id} e)))) {:type-id type-id
:prefixed? prefixed?} e))))
(throw (throw
(ex-info (ex-info
(str "No reader provided for custom type with internal id: " (str "No reader provided for custom type id: " type-id)
type-id) {:type-id type-id
{:internal-type-id type-id})))) :prefixed? prefixed?}))))
(defn- read-edn [edn] (defn- read-edn [edn]
(try (try
@ -1127,9 +1128,14 @@
(fn [] (thaw-from-in! in)))) (fn [] (thaw-from-in! in))))
;; ----------------------------------------------------------------- ;; -----------------------------------------------------------------
id-prefixed-custom (read-custom! in (.readShort in)) id-prefixed-custom (read-custom! in :prefixed (.readShort in))
(read-custom! in type-id) ; Unprefixed custom type (catchall)
) (if (neg? type-id)
(read-custom! in nil type-id) ; Unprefixed custom type
(throw
(ex-info
(str "Unrecognized type id (" type-id "). Data frozen with newer Nippy version?")
{:type-id type-id}))))
(catch Exception e (catch Exception e
(throw (ex-info (str "Thaw failed against type-id: " type-id) (throw (ex-info (str "Thaw failed against type-id: " type-id)