client: Remove MissingContext panic

Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
This commit is contained in:
Evgenii Baidakov 2023-05-17 12:55:36 +04:00
parent cfdd870755
commit cb4acec6a2
No known key found for this signature in database
GPG key ID: 8733EE3D72CDB4DE
12 changed files with 0 additions and 70 deletions

View file

@ -45,8 +45,6 @@ func (x ResBalanceGet) Amount() accounting.Decimal {
// Context is required and must not be nil. It is used for network communication. // Context is required and must not be nil. It is used for network communication.
func (c *Client) BalanceGet(ctx context.Context, prm PrmBalanceGet) (*ResBalanceGet, error) { func (c *Client) BalanceGet(ctx context.Context, prm PrmBalanceGet) (*ResBalanceGet, error) {
switch { switch {
case ctx == nil:
panic(panicMsgMissingContext)
case !prm.accountSet: case !prm.accountSet:
panic("account not set") panic("account not set")
} }

View file

@ -49,7 +49,6 @@ func writeXHeadersToMeta(xHeaders []string, h *v2session.RequestMetaHeader) {
// panic messages. // panic messages.
const ( const (
panicMsgMissingContext = "missing context"
panicMsgMissingContainer = "missing container" panicMsgMissingContainer = "missing container"
panicMsgMissingObject = "missing object" panicMsgMissingObject = "missing object"
panicMsgOwnerExtract = "extract owner failed" panicMsgOwnerExtract = "extract owner failed"

View file

@ -89,8 +89,6 @@ func (c *Client) defaultSigner() neofscrypto.Signer {
func (c *Client) ContainerPut(ctx context.Context, prm PrmContainerPut) (*ResContainerPut, error) { func (c *Client) ContainerPut(ctx context.Context, prm PrmContainerPut) (*ResContainerPut, error) {
// check parameters // check parameters
switch { switch {
case ctx == nil:
panic(panicMsgMissingContext)
case !prm.cnrSet: case !prm.cnrSet:
panic(panicMsgMissingContainer) panic(panicMsgMissingContainer)
} }
@ -210,8 +208,6 @@ func (x ResContainerGet) Container() container.Container {
// Context is required and must not be nil. It is used for network communication. // Context is required and must not be nil. It is used for network communication.
func (c *Client) ContainerGet(ctx context.Context, prm PrmContainerGet) (*ResContainerGet, error) { func (c *Client) ContainerGet(ctx context.Context, prm PrmContainerGet) (*ResContainerGet, error) {
switch { switch {
case ctx == nil:
panic(panicMsgMissingContext)
case !prm.idSet: case !prm.idSet:
panic(panicMsgMissingContainer) panic(panicMsgMissingContainer)
} }
@ -301,8 +297,6 @@ func (x ResContainerList) Containers() []cid.ID {
func (c *Client) ContainerList(ctx context.Context, prm PrmContainerList) (*ResContainerList, error) { func (c *Client) ContainerList(ctx context.Context, prm PrmContainerList) (*ResContainerList, error) {
// check parameters // check parameters
switch { switch {
case ctx == nil:
panic(panicMsgMissingContext)
case !prm.ownerSet: case !prm.ownerSet:
panic("account not set") panic("account not set")
} }
@ -409,8 +403,6 @@ func (x *PrmContainerDelete) WithinSession(tok session.Container) {
func (c *Client) ContainerDelete(ctx context.Context, prm PrmContainerDelete) error { func (c *Client) ContainerDelete(ctx context.Context, prm PrmContainerDelete) error {
// check parameters // check parameters
switch { switch {
case ctx == nil:
panic(panicMsgMissingContext)
case !prm.idSet: case !prm.idSet:
panic(panicMsgMissingContainer) panic(panicMsgMissingContainer)
} }
@ -515,8 +507,6 @@ func (x ResContainerEACL) Table() eacl.Table {
func (c *Client) ContainerEACL(ctx context.Context, prm PrmContainerEACL) (*ResContainerEACL, error) { func (c *Client) ContainerEACL(ctx context.Context, prm PrmContainerEACL) (*ResContainerEACL, error) {
// check parameters // check parameters
switch { switch {
case ctx == nil:
panic(panicMsgMissingContext)
case !prm.idSet: case !prm.idSet:
panic(panicMsgMissingContainer) panic(panicMsgMissingContainer)
} }
@ -624,8 +614,6 @@ func (x *PrmContainerSetEACL) WithinSession(s session.Container) {
func (c *Client) ContainerSetEACL(ctx context.Context, prm PrmContainerSetEACL) error { func (c *Client) ContainerSetEACL(ctx context.Context, prm PrmContainerSetEACL) error {
// check parameters // check parameters
switch { switch {
case ctx == nil:
panic(panicMsgMissingContext)
case !prm.tableSet: case !prm.tableSet:
panic("eACL table not set") panic("eACL table not set")
} }
@ -725,8 +713,6 @@ func (x *PrmAnnounceSpace) SetValues(vs []container.SizeEstimation) {
func (c *Client) ContainerAnnounceUsedSpace(ctx context.Context, prm PrmAnnounceSpace) error { func (c *Client) ContainerAnnounceUsedSpace(ctx context.Context, prm PrmAnnounceSpace) error {
// check parameters // check parameters
switch { switch {
case ctx == nil:
panic(panicMsgMissingContext)
case len(prm.announcements) == 0: case len(prm.announcements) == 0:
panic("missing announcements") panic("missing announcements")
} }

View file

@ -41,17 +41,9 @@ func (x ResEndpointInfo) NodeInfo() netmap.NodeInfo {
// Any client's internal or transport errors are returned as `error`, // Any client's internal or transport errors are returned as `error`,
// see [apistatus] package for NeoFS-specific error types. // see [apistatus] package for NeoFS-specific error types.
// //
// Immediately panics if parameters are set incorrectly (see PrmEndpointInfo docs).
// Context is required and must not be nil. It is used for network communication.
//
// Exactly one return value is non-nil. Server status return is returned in ResEndpointInfo. // Exactly one return value is non-nil. Server status return is returned in ResEndpointInfo.
// Reflects all internal errors in second return value (transport problems, response processing, etc.). // Reflects all internal errors in second return value (transport problems, response processing, etc.).
func (c *Client) EndpointInfo(ctx context.Context, prm PrmEndpointInfo) (*ResEndpointInfo, error) { func (c *Client) EndpointInfo(ctx context.Context, prm PrmEndpointInfo) (*ResEndpointInfo, error) {
// check context
if ctx == nil {
panic(panicMsgMissingContext)
}
// form request // form request
var req v2netmap.LocalNodeInfoRequest var req v2netmap.LocalNodeInfoRequest
@ -130,17 +122,9 @@ func (x ResNetworkInfo) Info() netmap.NetworkInfo {
// Any client's internal or transport errors are returned as `error`, // Any client's internal or transport errors are returned as `error`,
// see [apistatus] package for NeoFS-specific error types. // see [apistatus] package for NeoFS-specific error types.
// //
// Immediately panics if parameters are set incorrectly (see PrmNetworkInfo docs).
// Context is required and must not be nil. It is used for network communication.
//
// Exactly one return value is non-nil. Server status return is returned in ResNetworkInfo. // Exactly one return value is non-nil. Server status return is returned in ResNetworkInfo.
// Reflects all internal errors in second return value (transport problems, response processing, etc.). // Reflects all internal errors in second return value (transport problems, response processing, etc.).
func (c *Client) NetworkInfo(ctx context.Context, prm PrmNetworkInfo) (*ResNetworkInfo, error) { func (c *Client) NetworkInfo(ctx context.Context, prm PrmNetworkInfo) (*ResNetworkInfo, error) {
// check context
if ctx == nil {
panic(panicMsgMissingContext)
}
// form request // form request
var req v2netmap.NetworkInfoRequest var req v2netmap.NetworkInfoRequest
@ -207,11 +191,6 @@ func (x ResNetMapSnapshot) NetMap() netmap.NetMap {
// Exactly one return value is non-nil. Server status return is returned in ResNetMapSnapshot. // Exactly one return value is non-nil. Server status return is returned in ResNetMapSnapshot.
// Reflects all internal errors in second return value (transport problems, response processing, etc.). // Reflects all internal errors in second return value (transport problems, response processing, etc.).
func (c *Client) NetMapSnapshot(ctx context.Context, _ PrmNetMapSnapshot) (*ResNetMapSnapshot, error) { func (c *Client) NetMapSnapshot(ctx context.Context, _ PrmNetMapSnapshot) (*ResNetMapSnapshot, error) {
// check context
if ctx == nil {
panic(panicMsgMissingContext)
}
// form request body // form request body
var body v2netmap.SnapshotRequestBody var body v2netmap.SnapshotRequestBody

View file

@ -82,12 +82,6 @@ func TestClient_NetMapSnapshot(t *testing.T) {
c := newClient(signer, &srv) c := newClient(signer, &srv)
ctx := context.Background() ctx := context.Background()
// missing context
require.PanicsWithValue(t, panicMsgMissingContext, func() {
//nolint:staticcheck
_, _ = c.NetMapSnapshot(nil, prm)
})
// request signature // request signature
srv.errTransport = errors.New("any error") srv.errTransport = errors.New("any error")

View file

@ -125,8 +125,6 @@ func (x ResObjectDelete) Tombstone() oid.ID {
// - [apistatus.ErrSessionTokenExpired]. // - [apistatus.ErrSessionTokenExpired].
func (c *Client) ObjectDelete(ctx context.Context, prm PrmObjectDelete) (*ResObjectDelete, error) { func (c *Client) ObjectDelete(ctx context.Context, prm PrmObjectDelete) (*ResObjectDelete, error) {
switch { switch {
case ctx == nil:
panic(panicMsgMissingContext)
case prm.addr.GetContainerID() == nil: case prm.addr.GetContainerID() == nil:
panic(panicMsgMissingContainer) panic(panicMsgMissingContainer)
case prm.addr.GetObjectID() == nil: case prm.addr.GetObjectID() == nil:

View file

@ -294,8 +294,6 @@ func (x *ObjectReader) Read(p []byte) (int, error) {
func (c *Client) ObjectGetInit(ctx context.Context, prm PrmObjectGet) (*ObjectReader, error) { func (c *Client) ObjectGetInit(ctx context.Context, prm PrmObjectGet) (*ObjectReader, error) {
// check parameters // check parameters
switch { switch {
case ctx == nil:
panic(panicMsgMissingContext)
case prm.addr.GetContainerID() == nil: case prm.addr.GetContainerID() == nil:
panic(panicMsgMissingContainer) panic(panicMsgMissingContainer)
case prm.addr.GetObjectID() == nil: case prm.addr.GetObjectID() == nil:
@ -400,8 +398,6 @@ func (x *ResObjectHead) ReadHeader(dst *object.Object) bool {
// - [apistatus.ErrSessionTokenExpired]. // - [apistatus.ErrSessionTokenExpired].
func (c *Client) ObjectHead(ctx context.Context, prm PrmObjectHead) (*ResObjectHead, error) { func (c *Client) ObjectHead(ctx context.Context, prm PrmObjectHead) (*ResObjectHead, error) {
switch { switch {
case ctx == nil:
panic(panicMsgMissingContext)
case prm.addr.GetContainerID() == nil: case prm.addr.GetContainerID() == nil:
panic(panicMsgMissingContainer) panic(panicMsgMissingContainer)
case prm.addr.GetObjectID() == nil: case prm.addr.GetObjectID() == nil:
@ -644,8 +640,6 @@ func (x *ObjectRangeReader) Read(p []byte) (int, error) {
func (c *Client) ObjectRangeInit(ctx context.Context, prm PrmObjectRange) (*ObjectRangeReader, error) { func (c *Client) ObjectRangeInit(ctx context.Context, prm PrmObjectRange) (*ObjectRangeReader, error) {
// check parameters // check parameters
switch { switch {
case ctx == nil:
panic(panicMsgMissingContext)
case prm.addr.GetContainerID() == nil: case prm.addr.GetContainerID() == nil:
panic(panicMsgMissingContainer) panic(panicMsgMissingContainer)
case prm.addr.GetObjectID() == nil: case prm.addr.GetObjectID() == nil:

View file

@ -156,8 +156,6 @@ func (x ResObjectHash) Checksums() [][]byte {
// Context is required and must not be nil. It is used for network communication. // Context is required and must not be nil. It is used for network communication.
func (c *Client) ObjectHash(ctx context.Context, prm PrmObjectHash) (*ResObjectHash, error) { func (c *Client) ObjectHash(ctx context.Context, prm PrmObjectHash) (*ResObjectHash, error) {
switch { switch {
case ctx == nil:
panic(panicMsgMissingContext)
case prm.addr.GetContainerID() == nil: case prm.addr.GetContainerID() == nil:
panic(panicMsgMissingContainer) panic(panicMsgMissingContainer)
case prm.addr.GetObjectID() == nil: case prm.addr.GetObjectID() == nil:

View file

@ -233,11 +233,6 @@ func (x *ObjectWriter) Close() (*ResObjectPut, error) {
// //
// Context is required and must not be nil. It is used for network communication. // Context is required and must not be nil. It is used for network communication.
func (c *Client) ObjectPutInit(ctx context.Context, prm PrmObjectPutInit) (*ObjectWriter, error) { func (c *Client) ObjectPutInit(ctx context.Context, prm PrmObjectPutInit) (*ObjectWriter, error) {
// check parameters
if ctx == nil {
panic(panicMsgMissingContext)
}
var w ObjectWriter var w ObjectWriter
ctx, cancel := context.WithCancel(ctx) ctx, cancel := context.WithCancel(ctx)

View file

@ -210,8 +210,6 @@ func (x *ObjectListReader) Close() error {
func (c *Client) ObjectSearchInit(ctx context.Context, prm PrmObjectSearch) (*ObjectListReader, error) { func (c *Client) ObjectSearchInit(ctx context.Context, prm PrmObjectSearch) (*ObjectListReader, error) {
// check parameters // check parameters
switch { switch {
case ctx == nil:
panic(panicMsgMissingContext)
case !prm.cnrSet: case !prm.cnrSet:
panic(panicMsgMissingContainer) panic(panicMsgMissingContainer)
} }

View file

@ -42,8 +42,6 @@ func (x *PrmAnnounceLocalTrust) SetValues(trusts []reputation.Trust) {
func (c *Client) AnnounceLocalTrust(ctx context.Context, prm PrmAnnounceLocalTrust) error { func (c *Client) AnnounceLocalTrust(ctx context.Context, prm PrmAnnounceLocalTrust) error {
// check parameters // check parameters
switch { switch {
case ctx == nil:
panic(panicMsgMissingContext)
case prm.epoch == 0: case prm.epoch == 0:
panic("zero epoch") panic("zero epoch")
case len(prm.trusts) == 0: case len(prm.trusts) == 0:
@ -130,8 +128,6 @@ func (x *PrmAnnounceIntermediateTrust) SetCurrentValue(trust reputation.PeerToPe
func (c *Client) AnnounceIntermediateTrust(ctx context.Context, prm PrmAnnounceIntermediateTrust) error { func (c *Client) AnnounceIntermediateTrust(ctx context.Context, prm PrmAnnounceIntermediateTrust) error {
// check parameters // check parameters
switch { switch {
case ctx == nil:
panic(panicMsgMissingContext)
case prm.epoch == 0: case prm.epoch == 0:
panic("zero epoch") panic("zero epoch")
case !prm.trustSet: case !prm.trustSet:

View file

@ -67,11 +67,6 @@ func (x ResSessionCreate) PublicKey() []byte {
// Immediately panics if parameters are set incorrectly (see PrmSessionCreate docs). // Immediately panics if parameters are set incorrectly (see PrmSessionCreate docs).
// Context is required and must not be nil. It is used for network communication. // Context is required and must not be nil. It is used for network communication.
func (c *Client) SessionCreate(ctx context.Context, prm PrmSessionCreate) (*ResSessionCreate, error) { func (c *Client) SessionCreate(ctx context.Context, prm PrmSessionCreate) (*ResSessionCreate, error) {
// check context
if ctx == nil {
panic(panicMsgMissingContext)
}
var ownerID user.ID var ownerID user.ID
if err := user.IDFromSigner(&ownerID, prm.signer); err != nil { if err := user.IDFromSigner(&ownerID, prm.signer); err != nil {
panic(panicMsgOwnerExtract) panic(panicMsgOwnerExtract)