From 39080a8a05f2d32afcd54273e571ccf3db12e983 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Tue, 8 Aug 2023 10:54:38 +0200 Subject: [PATCH] #136: Add error handling to message writing process In the updated version of msgwriter.go, an additional error handling process has been included. If an error is detected when creating a new part in the message writer, this error is stored and prevents executing the writeBody function. This fixes nil pointer dereference in `mw.writeBody` if an error occured previously --- msgwriter.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/msgwriter.go b/msgwriter.go index c0e4b88..f386ca7 100644 --- a/msgwriter.go +++ b/msgwriter.go @@ -230,8 +230,12 @@ func (mw *msgWriter) addFiles(fl []*File, a bool) { } if mw.d > 0 { mw.newPart(f.Header) + mw.err = fmt.Errorf("ERROR") + } + + if mw.err == nil { + mw.writeBody(f.Writer, e) } - mw.writeBody(f.Writer, e) } }