From 9a2b0a068b587772b0163a68722a6970c929eb5d Mon Sep 17 00:00:00 2001 From: Peter Taoussanis Date: Tue, 18 Jun 2013 09:49:42 +0700 Subject: [PATCH] `thaw` API should throw on first non-legacy error --- README.md | 2 +- project.clj | 4 ++-- src/clj/taoensso/nippy.clj | 11 ++++++++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 4af8711..358eecd 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Current [semantic](http://semver.org/) version: ```clojure [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!** diff --git a/project.clj b/project.clj index b81e797..7902c02 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject com.taoensso/nippy "2.0.0-alpha9" +(defproject com.taoensso/nippy "2.0.0-alpha10" :description "Clojure serialization library" :url "https://github.com/ptaoussanis/nippy" :license {:name "Eclipse Public License" @@ -22,4 +22,4 @@ :min-lein-version "2.0.0" :warn-on-reflection true :source-paths ["src/clj"] - :java-source-paths ["src/java"]) + :java-source-paths ["src/java"]) \ No newline at end of file diff --git a/src/clj/taoensso/nippy.clj b/src/clj/taoensso/nippy.clj index ceac984..ec4f7ac 100644 --- a/src/clj/taoensso/nippy.clj +++ b/src/clj/taoensso/nippy.clj @@ -296,7 +296,7 @@ (if-let [[data-ba {:keys [unrecognized-header? compressed? encrypted?] :as head-meta}] (try-parse-header ba)] - (cond ; Header appears okay + (cond ; Header _appears_ okay (and (not legacy-opts) unrecognized-header?) ; Conservative (ex "Unrecognized header. Data frozen with newer Nippy version?") (and compressed? (not compressor)) @@ -305,10 +305,15 @@ (if (::tools-thaw? opts) ::need-password (ex "Encrypted data. Try again with password.")) :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 - (try-thaw-data ba nil)))) + (if legacy-opts + (try-thaw-data ba nil) + (ex "Unfrozen or corrupt data?"))))) (comment (thaw (freeze "hello")) (thaw (freeze "hello" {:compressor nil}))