Skip to content

Commit

Permalink
Merge pull request #316 from FundingCircle/enrich-serializer-exceptio…
Browse files Browse the repository at this point in the history
…n-info

[TDI-1361] make the avro serialization exception message more verbose
  • Loading branch information
apanourgiasfc authored May 23, 2022
2 parents bac4feb + 0ce194e commit a36a81a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
## Unreleased


### [0.9.4] - [2022-05-23]

* More verbose avro serialization exception errors

### [0.9.3] - [2021-11-24]

* Move libraries overrides back to dependencies.
Expand Down
25 changes: 17 additions & 8 deletions src/jackdaw/serdes/avro.clj
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
[java.io ByteArrayOutputStream ByteArrayInputStream]
[java.util Collection Map UUID]
[org.apache.avro
Schema$Parser Schema$ArraySchema Schema Schema$Field]
AvroTypeException Schema$Parser Schema$ArraySchema Schema Schema$Field]
[org.apache.avro.io
EncoderFactory DecoderFactory JsonEncoder]
[org.apache.avro.generic
Expand Down Expand Up @@ -149,7 +149,8 @@
(defn validate-clj! [this x path expected-type]
(when-not (match-clj? this x)
(throw (ex-info (serialization-error-msg x expected-type)
{:path path, :data x}))))
{:path path, :data x}
(AvroTypeException. "Type Error")))))

;;;; Primitive Types

Expand Down Expand Up @@ -428,7 +429,8 @@
(clj->avro [_ clj-map path]
(when-not (map? clj-map)
(throw (ex-info (serialization-error-msg clj-map "record")
{:path path, :clj-data clj-map})))
{:path path, :clj-data clj-map}
(AvroTypeException. "Type Error"))))

(let [record-builder (GenericRecordBuilder. schema)]
(try
Expand Down Expand Up @@ -485,7 +487,8 @@
(map #(.getType ^Schema %))
(str/join ", ")
(format "union [%s]")))
{:path path, :clj-data clj-data})))))
{:path path, :clj-data clj-data}
(AvroTypeException. "Type Error"))))))

(defn ->UnionType
"Wrapper by which to construct a `UnionType` which handles the
Expand Down Expand Up @@ -523,10 +526,16 @@
(try
(.serialize base-serializer topic (clj->avro coercion-type data []))
(catch clojure.lang.ExceptionInfo e
(let [data (-> e
ex-data
(assoc :topic topic :clj-data data))]
(throw (ex-info (.getMessage e) data))))))}
(let [exception-data (-> e
ex-data
(assoc :topic topic :clj-data data))
path (:path exception-data)
exception-message (str (merge {:message (.getMessage e)
:topic (:topic exception-data)
:path path}
(when (instance? org.apache.avro.AvroTypeException (ex-cause e))
{:data (get-in data path)})))]
(throw (ex-info exception-message exception-data))))))}
clj-serializer (fn/new-serializer methods)]
(.configure ^Serializer clj-serializer serializer-config key?)
clj-serializer))
Expand Down

0 comments on commit a36a81a

Please sign in to comment.