From 01c026041cd39b49edd0e20c7a24c04d95270469 Mon Sep 17 00:00:00 2001 From: Nikolay Sivko Date: Thu, 18 May 2023 17:41:58 +0300 Subject: [PATCH] recovering from panics while parsing `bson` documents (#16) --- tracing/mongo.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tracing/mongo.go b/tracing/mongo.go index 4d8f6dc..fe217d6 100644 --- a/tracing/mongo.go +++ b/tracing/mongo.go @@ -56,10 +56,13 @@ func parseMongo(payload []byte) string { return bsonToString(reader) } -func bsonToString(r io.Reader) string { - raw, err := bson.NewFromIOReader(r) - if err != nil { - return "" +func bsonToString(r io.Reader) (res string) { + res = "" + defer func() { + recover() + }() + if raw, err := bson.NewFromIOReader(r); err == nil { + res = raw.String() } - return raw.String() + return }