0
Fork 0
mirror of https://github.com/willnorris/imageproxy.git synced 2024-12-16 21:56:43 -05:00

lint: improve error handling

This commit is contained in:
Will Norris 2022-01-22 10:29:37 -08:00
parent ef8aec77a9
commit a81add5d96
6 changed files with 9 additions and 5 deletions

View file

@ -2,6 +2,7 @@ linters:
enable:
- dogsled
- dupl
- errorlint
- goimports
- gosec
- misspell

View file

@ -53,7 +53,7 @@ func sign(key string, s string, urlOnly bool) ([]byte, error) {
k, err := parseKey(key)
if err != nil {
return nil, fmt.Errorf("error parsing key: %v", err)
return nil, fmt.Errorf("error parsing key: %w", err)
}
mac := hmac.New(sha256.New, k)

View file

@ -161,7 +161,7 @@ func parseCache(c string) (imageproxy.Cache, error) {
u, err := url.Parse(c)
if err != nil {
return nil, fmt.Errorf("error parsing cache flag: %v", err)
return nil, fmt.Errorf("error parsing cache flag: %w", err)
}
switch u.Scheme {

View file

@ -276,7 +276,7 @@ func (p *Proxy) serveImage(w http.ResponseWriter, r *http.Request) {
// the content type. Returns empty string if error occurs.
func peekContentType(p *bufio.Reader) string {
byt, err := p.Peek(512)
if err != nil && err != bufio.ErrBufferFull && err != io.EOF {
if err != nil && !errors.Is(err, bufio.ErrBufferFull) && !errors.Is(err, io.EOF) {
return ""
}
return http.DetectContentType(byt)

View file

@ -9,6 +9,7 @@ import (
"context"
"crypto/md5"
"encoding/hex"
"errors"
"io"
"io/ioutil"
"log"
@ -27,7 +28,7 @@ type cache struct {
func (c *cache) Get(key string) ([]byte, bool) {
r, err := c.object(key).NewReader(ctx)
if err != nil {
if err != storage.ErrObjectNotExist {
if !errors.Is(err, storage.ErrObjectNotExist) {
log.Printf("error reading from gcs: %v", err)
}
return nil, false

View file

@ -9,6 +9,7 @@ import (
"bytes"
"crypto/md5"
"encoding/hex"
"errors"
"io"
"io/ioutil"
"log"
@ -36,7 +37,8 @@ func (c *cache) Get(key string) ([]byte, bool) {
resp, err := c.GetObject(input)
if err != nil {
if aerr, ok := err.(awserr.Error); ok && aerr.Code() != "NoSuchKey" {
var aerr awserr.Error
if errors.As(err, &aerr) && aerr.Code() != "NoSuchKey" {
log.Printf("error fetching from s3: %v", aerr)
}
return nil, false