Add errors check if ErrorChannel or ErrorResolver is nil on StartClient

This commit is contained in:
qowevisa 2024-10-12 12:35:14 +03:00
parent 6bb8dc19b1
commit e94bbb8901

View File

@ -53,7 +53,21 @@ func CreateClient(addr string, options ...ClientOption) *Client {
} }
} }
var (
ERROR_CLIENT_ERRRSL_NIL = errors.New("Error Resolver is nil")
ERROR_CLIENT_ERRCHL_NIL = errors.New("Error Channel is nil")
)
func (c *Client) StartClient() error { func (c *Client) StartClient() error {
if c.Status&statusBitCustomErrorHandling == 0 {
if c.ErrorResolver == nil {
return fmt.Errorf("Can't start client: %w", ERROR_CLIENT_ERRRSL_NIL)
}
if c.ErrorResolver == nil {
return fmt.Errorf("Can't start client: %w", ERROR_CLIENT_ERRCHL_NIL)
}
go c.ErrorResolver(c.ErrorsChannel)
}
server, err := net.Dial("tcp", c.addr) server, err := net.Dial("tcp", c.addr)
if err != nil { if err != nil {
return fmt.Errorf("net.Dial: %w", err) return fmt.Errorf("net.Dial: %w", err)