From 35f92f2ddc325944bb70c0638dab55b5b4e27625 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Wed, 23 Oct 2024 13:51:31 +0200 Subject: [PATCH] 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. --- client.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/client.go b/client.go index af36b47..2e48358 100644 --- a/client.go +++ b/client.go @@ -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 }