Skip to content

Commit

Permalink
recovering from panics while parsing bson documents (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
def committed May 18, 2023
1 parent e10593c commit 01c0260
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions tracing/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<truncated>"
func bsonToString(r io.Reader) (res string) {
res = "<truncated>"
defer func() {
recover()
}()
if raw, err := bson.NewFromIOReader(r); err == nil {
res = raw.String()
}
return raw.String()
return
}

0 comments on commit 01c0260

Please sign in to comment.