From fd9cbad5db327f58320050343cb97320e7a633da Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Mon, 5 Aug 2024 12:03:51 -0700 Subject: [PATCH] feat: add exception for mime.ErrInvalidMediaParameter It is documented ([1]) that mime.ParseMediaType can return mime.ErrInvalidMediaParameter error, so it's not a bug to perform a direct comparison. [1]: https://pkg.go.dev/mime#ParseMediaType Signed-off-by: Kir Kolyshkin --- errorlint/allowed.go | 2 ++ errorlint/testdata/src/allowed/allowed.go | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/errorlint/allowed.go b/errorlint/allowed.go index 791e50f..cf48170 100644 --- a/errorlint/allowed.go +++ b/errorlint/allowed.go @@ -57,6 +57,8 @@ func setDefaultAllowedErrors() { {Err: "io.ErrUnexpectedEOF", Fun: "io.ReadAtLeast"}, {Err: "io.EOF", Fun: "io.ReadFull"}, {Err: "io.ErrUnexpectedEOF", Fun: "io.ReadFull"}, + // pkg/mime + {Err: "mime.ErrInvalidMediaParameter", Fun: "mime.ParseMediaType"}, // pkg/net/http {Err: "net/http.ErrServerClosed", Fun: "(*net/http.Server).ListenAndServe"}, {Err: "net/http.ErrServerClosed", Fun: "(*net/http.Server).ListenAndServeTLS"}, diff --git a/errorlint/testdata/src/allowed/allowed.go b/errorlint/testdata/src/allowed/allowed.go index 3090fb3..e3ff1ce 100644 --- a/errorlint/testdata/src/allowed/allowed.go +++ b/errorlint/testdata/src/allowed/allowed.go @@ -11,6 +11,7 @@ import ( "errors" "fmt" "io" + "mime" "mime/multipart" "net/http" "os" @@ -283,6 +284,13 @@ func MIMEMultipartReadFrom(r io.Reader, boundary string, maxMemory int64) { } } +func MimeParseMediaType(contentType string) { + _, _, err := mime.ParseMediaType(contentType) + if err == mime.ErrInvalidMediaParameter { + fmt.Println(err) + } +} + func SyscallErrors() { err := syscall.Chmod("/dev/null", 0666) if err == syscall.EINVAL {