Skip to content

Commit 1764294

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

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

src/taoensso/msgpack/impl.clj

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,13 @@
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)
137+
:preview
138+
(try
139+
(let [out (pr-str x)] (subs out 0 (min 32 (count out))))
140+
(catch Throwable _ :unprintable))})))
142141

143142
;; Separate for CLJ-1381
144143
(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: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -272,14 +272,14 @@
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
279+
:preview
280+
(try
281+
(let [s (pr-str x)] (subs s 0 (min 32 (count s))))
282+
(catch :default _ :unprintable))})))))
283283

284284
;;;; Unpacking
285285

0 commit comments

Comments
 (0)