From f7e55c42f6e9453abbf0a7434051b3e91c4ea8f8 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 6 Mar 2024 15:33:58 +0100 Subject: [PATCH] message: handle Writer.Close errors in Entity.WriteTo --- entity.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/entity.go b/entity.go index a0858e5..ee2ebe6 100644 --- a/entity.go +++ b/entity.go @@ -187,9 +187,13 @@ func (e *Entity) WriteTo(w io.Writer) error { if err != nil { return err } - defer ew.Close() - return e.writeBodyTo(ew) + if err := e.writeBodyTo(ew); err != nil { + ew.Close() + return err + } + + return ew.Close() } // WalkFunc is the type of the function called for each part visited by Walk.