diff --git a/client/incus_images.go b/client/incus_images.go index 8d67f2a5a5f..d12747d2e1b 100644 --- a/client/incus_images.go +++ b/client/incus_images.go @@ -422,9 +422,14 @@ func (r *ProtocolIncus) CreateImage(image api.ImagesPost, args *ImageCreateArgs) w := multipart.NewWriter(pw) go func() { + var ioErr error defer func() { - w.Close() - pw.Close() + cerr := w.Close() + if ioErr == nil && cerr != nil { + ioErr = cerr + } + + _ = pw.CloseWithError(ioErr) }() // Metadata file