From 6e81e13e1bff5804c99cbaf1737b3ea9d77f34c4 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Wed, 20 Apr 2022 19:06:47 +0300 Subject: [PATCH] [#218] client: Decode status at io.EOF in the client-side stream Object service of NeoFS API contains one client-side stream method: object.Put. In client-side streams, server can return an error after processing stream message. In this case write method returns `io.EOF` and actual error reason is encoded in response status, which is obtained after `Close()`. Client library should process such case. Signed-off-by: Alex Vanin --- client/object_put.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/client/object_put.go b/client/object_put.go index 69c9bf2..9db0574 100644 --- a/client/object_put.go +++ b/client/object_put.go @@ -3,7 +3,9 @@ package client import ( "context" "crypto/ecdsa" + "errors" "fmt" + "io" "github.com/nspcc-dev/neofs-api-go/v2/acl" v2object "github.com/nspcc-dev/neofs-api-go/v2/object" @@ -171,7 +173,10 @@ func (x *ObjectWriter) WritePayloadChunk(chunk []byte) bool { func (x *ObjectWriter) Close() (*ResObjectPut, error) { defer x.cancelCtxStream() - if x.ctxCall.err != nil { + // Ignore io.EOF error, because it is expected error for client-side + // stream termination by the server. E.g. when stream contains invalid + // message. Server returns an error in response message (in status). + if x.ctxCall.err != nil && !errors.Is(x.ctxCall.err, io.EOF) { return nil, x.ctxCall.err }