thaw API should throw on first non-legacy error

This commit is contained in:
Peter Taoussanis 2013-06-18 09:49:42 +07:00
parent a2cdfba874
commit 9a2b0a068b
3 changed files with 11 additions and 6 deletions

View file

@ -2,7 +2,7 @@ Current [semantic](http://semver.org/) version:
```clojure ```clojure
[com.taoensso/nippy "1.2.1"] ; Stable [com.taoensso/nippy "1.2.1"] ; Stable
[com.taoensso/nippy "2.0.0-alpha9"] ; Development (notes below) [com.taoensso/nippy "2.0.0-alpha10"] ; Development (notes below)
``` ```
v2 adds pluggable compression, crypto support (also pluggable), an improved API (including much better error messages), easier integration into other tools/libraries, and hugely improved performance. It **is backwards compatible**, but please note that the old `freeze-to-bytes`/`thaw-from-bytes` API has been **deprecated** in favor of `freeze`/`thaw`. **PLEASE REPORT ANY PROBLEMS!** v2 adds pluggable compression, crypto support (also pluggable), an improved API (including much better error messages), easier integration into other tools/libraries, and hugely improved performance. It **is backwards compatible**, but please note that the old `freeze-to-bytes`/`thaw-from-bytes` API has been **deprecated** in favor of `freeze`/`thaw`. **PLEASE REPORT ANY PROBLEMS!**

View file

@ -1,4 +1,4 @@
(defproject com.taoensso/nippy "2.0.0-alpha9" (defproject com.taoensso/nippy "2.0.0-alpha10"
:description "Clojure serialization library" :description "Clojure serialization library"
:url "https://github.com/ptaoussanis/nippy" :url "https://github.com/ptaoussanis/nippy"
:license {:name "Eclipse Public License" :license {:name "Eclipse Public License"
@ -22,4 +22,4 @@
:min-lein-version "2.0.0" :min-lein-version "2.0.0"
:warn-on-reflection true :warn-on-reflection true
:source-paths ["src/clj"] :source-paths ["src/clj"]
:java-source-paths ["src/java"]) :java-source-paths ["src/java"])

View file

@ -296,7 +296,7 @@
(if-let [[data-ba {:keys [unrecognized-header? compressed? encrypted?] (if-let [[data-ba {:keys [unrecognized-header? compressed? encrypted?]
:as head-meta}] (try-parse-header ba)] :as head-meta}] (try-parse-header ba)]
(cond ; Header appears okay (cond ; Header _appears_ okay
(and (not legacy-opts) unrecognized-header?) ; Conservative (and (not legacy-opts) unrecognized-header?) ; Conservative
(ex "Unrecognized header. Data frozen with newer Nippy version?") (ex "Unrecognized header. Data frozen with newer Nippy version?")
(and compressed? (not compressor)) (and compressed? (not compressor))
@ -305,10 +305,15 @@
(if (::tools-thaw? opts) ::need-password (if (::tools-thaw? opts) ::need-password
(ex "Encrypted data. Try again with password.")) (ex "Encrypted data. Try again with password."))
:else (try (try-thaw-data data-ba head-meta) :else (try (try-thaw-data data-ba head-meta)
(catch Exception _ (try-thaw-data ba nil)))) (catch Exception e
(if legacy-opts
(try-thaw-data ba nil)
(throw e)))))
;; Header definitely not okay ;; Header definitely not okay
(try-thaw-data ba nil)))) (if legacy-opts
(try-thaw-data ba nil)
(ex "Unfrozen or corrupt data?")))))
(comment (thaw (freeze "hello")) (comment (thaw (freeze "hello"))
(thaw (freeze "hello" {:compressor nil})) (thaw (freeze "hello" {:compressor nil}))