bugsnag / bugsnag-go

Automatic panic monitoring for Go and Go web frameworks, like negroni, gin, and revel
https://docs.bugsnag.com/platforms/go
MIT License
203 stars 69 forks source link

Handle empty pointers to complex structs in metadata.Add #221

Closed DariaKunoichi closed 5 months ago

DariaKunoichi commented 6 months ago

Goal

When we pass a pointer to complex interface (that in Sanitizer gets caught in type switch-case) we don't check if the pointer is nil. Type specific switch-case tried to check for interface function String() for fmt.Stringer interface on the nil pointer leading to a panic.

Changeset

Moved check for nil pointers and interfaces before any other type matching is done. In metadata.AddStruct used an actual sanitized value to pass into metadata.Add.

Testing

New tests for adding pointers with Stringer interface to metadata - either nil ptr or normal.