client: Replace panics with errors in dial

Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
This commit is contained in:
Evgenii Baidakov 2023-05-17 14:11:33 +04:00
parent f9d740487a
commit ef887b3ab1
No known key found for this signature in database
GPG key ID: 8733EE3D72CDB4DE
2 changed files with 6 additions and 3 deletions

View file

@ -77,12 +77,12 @@ func (c *Client) Init(prm PrmInit) {
// See also Init / Close. // See also Init / Close.
func (c *Client) Dial(prm PrmDial) error { func (c *Client) Dial(prm PrmDial) error {
if prm.endpoint == "" { if prm.endpoint == "" {
panic("server address is unset or empty") return ErrMissingServer
} }
if prm.timeoutDialSet { if prm.timeoutDialSet {
if prm.timeoutDial <= 0 { if prm.timeoutDial <= 0 {
panic("non-positive timeout") return ErrNonPositiveTimeout
} }
} else { } else {
prm.timeoutDial = 5 * time.Second prm.timeoutDial = 5 * time.Second
@ -90,7 +90,7 @@ func (c *Client) Dial(prm PrmDial) error {
if prm.streamTimeoutSet { if prm.streamTimeoutSet {
if prm.streamTimeout <= 0 { if prm.streamTimeout <= 0 {
panic("non-positive timeout") return ErrNonPositiveTimeout
} }
} else { } else {
prm.streamTimeout = 10 * time.Second prm.streamTimeout = 10 * time.Second

View file

@ -6,6 +6,9 @@ import (
) )
var ( var (
ErrMissingServer = errors.New("server address is unset or empty")
ErrNonPositiveTimeout = errors.New("non-positive timeout")
ErrMissingContainer = errors.New("missing container") ErrMissingContainer = errors.New("missing container")
ErrMissingObject = errors.New("missing object") ErrMissingObject = errors.New("missing object")
ErrMissingAccount = errors.New("missing account") ErrMissingAccount = errors.New("missing account")