From 2b174c8b0b0b45f9c91ccd1c66de66016c933027 Mon Sep 17 00:00:00 2001 From: James Hillyerd Date: Tue, 20 Feb 2024 12:47:27 -0800 Subject: [PATCH] chore: resolve error & string related lint warnings (#507) Signed-off-by: James Hillyerd --- cmd/client/main.go | 3 +-- pkg/msghub/hub_test.go | 3 ++- pkg/policy/address.go | 29 +++++++++++++++-------------- pkg/server/smtp/handler.go | 3 ++- pkg/storage/file/fstore.go | 3 ++- 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/cmd/client/main.go b/cmd/client/main.go index 15c0556..cb99dea 100644 --- a/cmd/client/main.go +++ b/cmd/client/main.go @@ -70,8 +70,7 @@ func main() { } func baseURL() string { - return fmt.Sprintf("http://%s", - net.JoinHostPort(*host, strconv.FormatUint(uint64(*port), 10))) + return "http://%s" + net.JoinHostPort(*host, strconv.FormatUint(uint64(*port), 10)) } func fatal(msg string, err error) subcommands.ExitStatus { diff --git a/pkg/msghub/hub_test.go b/pkg/msghub/hub_test.go index fee893e..ad4c0c0 100644 --- a/pkg/msghub/hub_test.go +++ b/pkg/msghub/hub_test.go @@ -2,6 +2,7 @@ package msghub import ( "context" + "errors" "fmt" "strconv" "testing" @@ -51,7 +52,7 @@ func (l *testListener) Receive(msg event.MessageMetadata) error { close(l.overflow) } if l.errorAfter > 0 && l.gotEvents > l.errorAfter { - return fmt.Errorf("Too many messages") + return errors.New("too many messages") } return nil } diff --git a/pkg/policy/address.go b/pkg/policy/address.go index cfafda4..bb60186 100644 --- a/pkg/policy/address.go +++ b/pkg/policy/address.go @@ -2,6 +2,7 @@ package policy import ( "bytes" + "errors" "fmt" "net" "net/mail" @@ -136,7 +137,7 @@ func ParseEmailAddress(address string) (local string, domain string, err error) return "", "", err } if !ValidateDomainPart(domain) { - return "", "", fmt.Errorf("domain part validation failed") + return "", "", errors.New("domain part validation failed") } return local, domain, nil } @@ -240,26 +241,26 @@ func extractDomainMailbox(address string) (string, error) { // domain part is optional and not validated. func parseEmailAddress(address string) (local string, domain string, err error) { if address == "" { - return "", "", fmt.Errorf("empty address") + return "", "", errors.New("empty address") } if len(address) > 320 { - return "", "", fmt.Errorf("address exceeds 320 characters") + return "", "", errors.New("address exceeds 320 characters") } // Remove forward-path routes. if address[0] == '@' { end := strings.IndexRune(address, ':') if end == -1 { - return "", "", fmt.Errorf("missing terminating ':' in route specification") + return "", "", errors.New("missing terminating ':' in route specification") } address = address[end+1:] if address == "" { - return "", "", fmt.Errorf("address empty after removing route specification") + return "", "", errors.New("address empty after removing route specification") } } if address[0] == '.' { - return "", "", fmt.Errorf("address cannot start with a period") + return "", "", errors.New("address cannot start with a period") } // Loop over address parsing out local part. @@ -296,7 +297,7 @@ LOOP: // A single period is OK. if prev == '.' { // Sequence of periods is not permitted. - return "", "", fmt.Errorf("sequence of periods is not permitted") + return "", "", errors.New("sequence of periods is not permitted") } err = buf.WriteByte(c) if err != nil { @@ -319,7 +320,7 @@ LOOP: if i == 0 { inStringQuote = true } else { - return "", "", fmt.Errorf("quoted string can only begin at start of address") + return "", "", errors.New("quoted string can only begin at start of address") } } case c == '@': @@ -332,16 +333,16 @@ LOOP: } else { // End of local-part. if i > 128 { - return "", "", fmt.Errorf("local part must not exceed 128 characters") + return "", "", errors.New("local part must not exceed 128 characters") } if prev == '.' { - return "", "", fmt.Errorf("local part cannot end with a period") + return "", "", errors.New("local part cannot end with a period") } domain = address[i+1:] break LOOP } case c > 127: - return "", "", fmt.Errorf("characters outside of US-ASCII range not permitted") + return "", "", errors.New("characters outside of US-ASCII range not permitted") default: if inCharQuote || inStringQuote { err = buf.WriteByte(c) @@ -356,10 +357,10 @@ LOOP: prev = c } if inCharQuote { - return "", "", fmt.Errorf("cannot end address with unterminated quoted-pair") + return "", "", errors.New("cannot end address with unterminated quoted-pair") } if inStringQuote { - return "", "", fmt.Errorf("cannot end address with unterminated string quote") + return "", "", errors.New("cannot end address with unterminated string quote") } return buf.String(), domain, nil } @@ -370,7 +371,7 @@ LOOP: // quoted according to RFC3696. func parseMailboxName(localPart string) (result string, err error) { if localPart == "" { - return "", fmt.Errorf("mailbox name cannot be empty") + return "", errors.New("mailbox name cannot be empty") } result = strings.ToLower(localPart) invalid := make([]byte, 0, 10) diff --git a/pkg/server/smtp/handler.go b/pkg/server/smtp/handler.go index cdc1057..2713fe8 100644 --- a/pkg/server/smtp/handler.go +++ b/pkg/server/smtp/handler.go @@ -4,6 +4,7 @@ import ( "bufio" "bytes" "crypto/tls" + "errors" "fmt" "io" "net" @@ -310,7 +311,7 @@ func parseHelloArgument(arg string) (string, error) { domain = arg[:idx] } if domain == "" { - return "", fmt.Errorf("invalid domain") + return "", errors.New("invalid domain") } return domain, nil } diff --git a/pkg/storage/file/fstore.go b/pkg/storage/file/fstore.go index fec6afe..f3c2ec0 100644 --- a/pkg/storage/file/fstore.go +++ b/pkg/storage/file/fstore.go @@ -2,6 +2,7 @@ package file import ( "bufio" + "errors" "fmt" "io" "os" @@ -55,7 +56,7 @@ type Store struct { func New(cfg config.Storage, extHost *extension.Host) (storage.Store, error) { path := cfg.Params["path"] if path == "" { - return nil, fmt.Errorf("'path' parameter not specified") + return nil, errors.New("'path' parameter not specified") } mailPath := getMailPath(path)