2022-02-28 10:56:46 +00:00
|
|
|
package client
|
|
|
|
|
2022-06-27 07:39:20 +00:00
|
|
|
import (
|
2023-05-17 09:07:01 +00:00
|
|
|
"errors"
|
2022-08-05 07:56:49 +00:00
|
|
|
"fmt"
|
2022-06-27 07:39:20 +00:00
|
|
|
)
|
|
|
|
|
2023-05-15 03:45:06 +00:00
|
|
|
var (
|
2023-05-18 06:48:44 +00:00
|
|
|
// ErrMissingServer is returned when server endpoint is empty in parameters.
|
|
|
|
ErrMissingServer = errors.New("server address is unset or empty")
|
|
|
|
// ErrNonPositiveTimeout is returned when any timeout is below zero in parameters.
|
2023-05-17 10:11:33 +00:00
|
|
|
ErrNonPositiveTimeout = errors.New("non-positive timeout")
|
|
|
|
|
2023-05-18 06:48:44 +00:00
|
|
|
// ErrMissingContainer is returned when container is not provided.
|
|
|
|
ErrMissingContainer = errors.New("missing container")
|
|
|
|
// ErrMissingObject is returned when object is not provided.
|
|
|
|
ErrMissingObject = errors.New("missing object")
|
|
|
|
// ErrMissingAccount is returned when account/owner is not provided.
|
|
|
|
ErrMissingAccount = errors.New("missing account")
|
|
|
|
// ErrMissingEACL is returned when eACL table is not provided.
|
|
|
|
ErrMissingEACL = errors.New("missing eACL table")
|
|
|
|
// ErrMissingEACLContainer is returned when container info is not provided in eACL table.
|
2023-05-17 09:07:01 +00:00
|
|
|
ErrMissingEACLContainer = errors.New("missing container in eACL table")
|
2023-05-18 06:48:44 +00:00
|
|
|
// ErrMissingAnnouncements is returned when announcements are not provided.
|
2023-05-17 09:07:01 +00:00
|
|
|
ErrMissingAnnouncements = errors.New("missing announcements")
|
2023-05-18 06:48:44 +00:00
|
|
|
// ErrZeroRangeLength is returned when range parameter has zero length.
|
|
|
|
ErrZeroRangeLength = errors.New("zero range length")
|
|
|
|
// ErrMissingRanges is returned when empty ranges list is provided.
|
|
|
|
ErrMissingRanges = errors.New("missing ranges")
|
|
|
|
// ErrZeroEpoch is returned when zero epoch is provided.
|
|
|
|
ErrZeroEpoch = errors.New("zero epoch")
|
|
|
|
// ErrMissingTrusts is returned when empty slice of trusts is provided.
|
|
|
|
ErrMissingTrusts = errors.New("missing trusts")
|
|
|
|
// ErrMissingTrust is returned when empty trust is not provided.
|
|
|
|
ErrMissingTrust = errors.New("missing trust")
|
|
|
|
|
|
|
|
// ErrUnexpectedReadCall is returned when we already got all data but truing to get more.
|
2023-05-17 09:07:01 +00:00
|
|
|
ErrUnexpectedReadCall = errors.New("unexpected call to `Read`")
|
|
|
|
|
2023-05-18 06:48:44 +00:00
|
|
|
// ErrSign is returned when unable to sign service message.
|
2023-05-17 10:23:43 +00:00
|
|
|
ErrSign SignError
|
|
|
|
|
2023-05-18 06:56:16 +00:00
|
|
|
// ErrMissingResponseField is returned when required field is not exists in NeoFS api response.
|
|
|
|
ErrMissingResponseField MissingResponseFieldErr
|
2023-05-15 03:45:06 +00:00
|
|
|
)
|
|
|
|
|
2023-05-18 06:56:16 +00:00
|
|
|
// MissingResponseFieldErr contains field name which should be in NeoFS API response.
|
|
|
|
type MissingResponseFieldErr struct {
|
2023-05-15 03:45:06 +00:00
|
|
|
name string
|
|
|
|
}
|
|
|
|
|
2023-05-18 06:56:16 +00:00
|
|
|
// Error implements the error interface.
|
|
|
|
func (e MissingResponseFieldErr) Error() string {
|
2023-05-15 03:45:06 +00:00
|
|
|
return fmt.Sprintf("missing %s field in the response", e.name)
|
|
|
|
}
|
|
|
|
|
2023-05-18 06:56:16 +00:00
|
|
|
// Is implements interface for correct checking current error type with [errors.Is].
|
|
|
|
func (e MissingResponseFieldErr) Is(target error) bool {
|
2023-05-15 03:45:06 +00:00
|
|
|
switch target.(type) {
|
|
|
|
default:
|
|
|
|
return false
|
2023-05-18 06:56:16 +00:00
|
|
|
case MissingResponseFieldErr, *MissingResponseFieldErr:
|
2023-05-15 03:45:06 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-05 07:56:49 +00:00
|
|
|
// returns error describing missing field with the given name.
|
|
|
|
func newErrMissingResponseField(name string) error {
|
2023-05-18 06:56:16 +00:00
|
|
|
return MissingResponseFieldErr{name: name}
|
2022-08-05 07:56:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// returns error describing invalid field (according to the NeoFS protocol)
|
|
|
|
// with the given name and format violation err.
|
|
|
|
func newErrInvalidResponseField(name string, err error) error {
|
|
|
|
return fmt.Errorf("invalid %s field in the response: %w", name, err)
|
|
|
|
}
|
2023-05-17 10:23:43 +00:00
|
|
|
|
2023-05-18 06:48:44 +00:00
|
|
|
// SignError wraps another error with reason why sign process was failed.
|
2023-05-17 10:23:43 +00:00
|
|
|
type SignError struct {
|
|
|
|
err error
|
|
|
|
}
|
|
|
|
|
2023-05-18 06:48:44 +00:00
|
|
|
// NewSignError is a constructor for [SignError].
|
2023-05-17 10:23:43 +00:00
|
|
|
func NewSignError(err error) SignError {
|
|
|
|
return SignError{err: err}
|
|
|
|
}
|
|
|
|
|
2023-05-18 06:48:44 +00:00
|
|
|
// Error implements the error interface.
|
2023-05-17 10:23:43 +00:00
|
|
|
func (e SignError) Error() string {
|
|
|
|
return fmt.Sprintf("sign: %v", e.err)
|
|
|
|
}
|
|
|
|
|
2023-05-18 06:48:44 +00:00
|
|
|
// Unwrap implements the error interface.
|
2023-05-17 10:23:43 +00:00
|
|
|
func (e SignError) Unwrap() error {
|
|
|
|
return e.err
|
|
|
|
}
|
|
|
|
|
2023-05-18 06:48:44 +00:00
|
|
|
// Is implements interface for correct checking current error type with [errors.Is].
|
2023-05-17 10:23:43 +00:00
|
|
|
func (e SignError) Is(target error) bool {
|
|
|
|
switch target.(type) {
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
case SignError, *SignError:
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|