go-gmime
go-gmime copied to clipboard
Return error instead of panic
We should return an error, instead of panic'ing. Since this is a library, we should let the caller deal with the error.
For example, when calling parse.Recipients()
on a message with an empty To list:
(process:24446): GLib-GObject-CRITICAL **: g_object_unref: assertion 'G_IS_OBJECT (object)' failed
panic: ZERO pointer
goroutine 25 [running]:
panic(0x42edfa0, 0xc8201b8d10)
/usr/local/go/src/runtime/panic.go:464 +0x3e6
github.com/sendgrid/go-gmime/gmime.ref(0x0)
/Users/trevorrothaus/go/src/github.com/sendgrid/go-gmime/gmime/gmime.go:48 +0x75
github.com/sendgrid/go-gmime/gmime.AssignJanitor(0x5e00158, 0xc8201b46a8)
/Users/trevorrothaus/go/src/github.com/sendgrid/go-gmime/gmime/janitor.go:22 +0x39
github.com/sendgrid/go-gmime/gmime.CastPointer(0x0, 0x41c719f)
/Users/trevorrothaus/go/src/github.com/sendgrid/go-gmime/gmime/janitor.go:34 +0x81
github.com/sendgrid/go-gmime/gmime.CastInternetAddressList(0x0, 0x44bc748)
/Users/trevorrothaus/go/src/github.com/sendgrid/go-gmime/gmime/internet_address.go:189 +0x21
github.com/sendgrid/go-gmime/gmime.(*aMessage).AllRecipients(0xc8201b45e8, 0x0)
/Users/trevorrothaus/go/src/github.com/sendgrid/go-gmime/gmime/message.go:152 +0xc2
github.com/sendgrid/go-gmime/gmime.(*aParse).Recipients(0xc8201b8cd0, 0x0, 0x0)
/Users/trevorrothaus/go/src/github.com/sendgrid/go-gmime/gmime/parse.go:64 +0x45