Skip to content

Commit

Permalink
client: Return more clear error on head reading from ObjectHead
Browse files Browse the repository at this point in the history
Previously, on the problem with the 1st GET stream message, `Client`
returned 'header: ...' error. Such an error led to the question: header
what?

Now 'read header: ...' is returned.

Signed-off-by: Leonard Lyubich <[email protected]>
  • Loading branch information
cthulhu-rider committed Dec 10, 2024
1 parent a72d489 commit f3a65e3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion client/object_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ func (c *Client) ObjectGetInit(ctx context.Context, containerID cid.ID, objectID
}

if !r.readHeader(&hdr) {
err = fmt.Errorf("header: %w", r.Close())
err = fmt.Errorf("read header: %w", r.Close())
return hdr, nil, err
}

Expand Down
8 changes: 4 additions & 4 deletions client/object_get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@ func TestClient_ObjectGetInit(t *testing.T) {

srv.respondWithBody(0, b)
_, _, err := c.ObjectGetInit(ctx, anyCID, anyOID, anyValidSigner, anyValidOpts)
require.EqualError(t, err, "header: invalid split info: "+tc.msg)
require.EqualError(t, err, "read header: invalid split info: "+tc.msg)
})
}
})
Expand Down Expand Up @@ -1137,7 +1137,7 @@ func TestClient_ObjectGetInit(t *testing.T) {

srv.respondWithBody(0, b)
_, _, err := c.ObjectGetInit(ctx, anyCID, anyOID, anyValidSigner, anyValidOpts)
require.EqualError(t, err, "header: "+tc.msg)
require.EqualError(t, err, "read header: "+tc.msg)
})
}
})
Expand Down Expand Up @@ -1233,15 +1233,15 @@ func TestClient_ObjectGetInit(t *testing.T) {
_, _, err := c.ObjectGetInit(ctx, anyCID, anyOID, anyValidSigner, anyValidOpts)
_, ok := status.FromError(err)
require.False(t, ok)
require.EqualError(t, err, "header: %!w(<nil>)")
require.EqualError(t, err, "read header: %!w(<nil>)")
})
t.Run("chunk message first", func(t *testing.T) {
srv := newTestGetObjectServer()
c := newTestObjectClient(t, srv)

srv.respondWithBody(0, proto.Clone(validFullChunkObjectGetResponseBody).(*protoobject.GetResponse_Body))
_, _, err := c.ObjectGetInit(ctx, anyCID, anyOID, anyValidSigner, anyValidOpts)
require.EqualError(t, err, "header: unexpected message instead of heading part: *object.GetObjectPartChunk")
require.EqualError(t, err, "read header: unexpected message instead of heading part: *object.GetObjectPartChunk")
})
t.Run("repeated heading message", func(t *testing.T) {
srv := newTestGetObjectServer()
Expand Down

0 comments on commit f3a65e3

Please sign in to comment.