Skip to content

Commit

Permalink
feat: add exception for mime.ErrInvalidMediaParameter
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
kolyshkin authored and polyfloyd committed Aug 6, 2024
1 parent 1f1e448 commit 24f58bd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions errorlint/allowed.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
8 changes: 8 additions & 0 deletions errorlint/testdata/src/allowed/allowed.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"errors"
"fmt"
"io"
"mime"
"mime/multipart"
"net/http"
"os"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 24f58bd

Please sign in to comment.