Skip to content

Commit

Permalink
Add error handling for nil DialContextFunc
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wneessen committed Oct 23, 2024
1 parent 3251d74 commit 35f92f2
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 35f92f2

Please sign in to comment.