Add error handling for nil DialContextFunc

Introduce ErrDialContextFuncIsNil to handle cases where the dial context function is not provided. Update WithDialContextFunc to return this error when a nil function is passed.
This commit is contained in:
Winni Neessen 2024-10-23 13:51:31 +02:00
parent 3251d74c36
commit 35f92f2ddc
Signed by: wneessen
GPG key ID: 385AC9889632126E

View file

@ -245,6 +245,9 @@ var (
// ErrSMTPAuthMethodIsNil indicates that the SMTP authentication method provided is nil
ErrSMTPAuthMethodIsNil = errors.New("SMTP auth method is nil")
// ErrDialContextFuncIsNil indicates that a required dial context function is not provided.
ErrDialContextFuncIsNil = errors.New("dial context function is nil")
)
// NewClient creates a new Client instance with the provided host and optional configuration Option functions.
@ -677,6 +680,9 @@ func WithoutNoop() Option {
// - An Option function that sets the custom DialContextFunc for the Client.
func WithDialContextFunc(dialCtxFunc DialContextFunc) Option {
return func(c *Client) error {
if dialCtxFunc == nil {
return ErrDialContextFuncIsNil
}
c.dialContextFunc = dialCtxFunc
return nil
}