[#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 <alexey@nspcc.ru>
remotes/fyrchik/split-info-format
Alex Vanin 2022-04-20 19:06:47 +03:00 committed by LeL
parent 1ed426b8a6
commit 6e81e13e1b
1 changed files with 6 additions and 1 deletions

View File

@ -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
}