Skip to content

Commit 74295f9

Browse files
committed
[mod] Msgpack: throw when packing unsupported types
1 parent 4473cc1 commit 74295f9

File tree

2 files changed

+7
-16
lines changed

2 files changed

+7
-16
lines changed

src/taoensso/msgpack/impl.clj

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,9 @@
131131

132132
Object
133133
(pack-bytes [x ^DataOutput out]
134-
(pack-bytes
135-
{:msgpack/unpackable
136-
{:type (str (type x))
137-
:preview
138-
(try
139-
(let [out (pr-str x)] (subs out 0 (min 32 (count out))))
140-
(catch Throwable _ :unprintable))}}
141-
out)))
134+
(truss/ex-info!
135+
(str "Pack failed: unsupported type (" (type x) ")")
136+
{:type (type x), :value x})))
142137

143138
;; Separate for CLJ-1381
144139
(extend-protocol Packable (class (into-array Byte [])) (pack-bytes [a ^DataOutput out] (pack-bytes (byte-array a) out)))

src/taoensso/msgpack/impl.cljs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -272,14 +272,10 @@
272272
(pack-bytes [x out]
273273
(if (seqable? x)
274274
(pack-seq x out)
275-
(pack-bytes
276-
{:msgpack/unpackable
277-
{:type (enc/type-name x)
278-
:preview
279-
(try
280-
(let [s (pr-str x)] (subs s 0 (min 32 (count s))))
281-
(catch :default _ :unprintable))}}
282-
out))))
275+
(let [type-name (enc/type-name x)]
276+
(truss/ex-info!
277+
(str "Pack failed: unsupported type (" type-name ")")
278+
{:type type-name, :value x})))))
283279

284280
;;;; Unpacking
285281

0 commit comments

Comments
 (0)