From e3a10fc58d1de17b83f4a27140758d941aa4d420 Mon Sep 17 00:00:00 2001 From: Sasha Melentyev Date: Thu, 21 Jul 2022 19:36:27 +0300 Subject: [PATCH] chore: use errors.New instead of format function without args for error (#1134) --- config.go | 4 ++-- encoder.go | 2 +- http_handler.go | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/config.go b/config.go index 55637fb0b..ee6096766 100644 --- a/config.go +++ b/config.go @@ -21,7 +21,7 @@ package zap import ( - "fmt" + "errors" "sort" "time" @@ -182,7 +182,7 @@ func (cfg Config) Build(opts ...Option) (*Logger, error) { } if cfg.Level == (AtomicLevel{}) { - return nil, fmt.Errorf("missing Level") + return nil, errors.New("missing Level") } log := New( diff --git a/encoder.go b/encoder.go index 08ed83354..caa04ceef 100644 --- a/encoder.go +++ b/encoder.go @@ -63,7 +63,7 @@ func RegisterEncoder(name string, constructor func(zapcore.EncoderConfig) (zapco func newEncoder(name string, encoderConfig zapcore.EncoderConfig) (zapcore.Encoder, error) { if encoderConfig.TimeKey != "" && encoderConfig.EncodeTime == nil { - return nil, fmt.Errorf("missing EncodeTime in EncoderConfig") + return nil, errors.New("missing EncodeTime in EncoderConfig") } _encoderMutex.RLock() diff --git a/http_handler.go b/http_handler.go index 1297c33b3..d3a271c7d 100644 --- a/http_handler.go +++ b/http_handler.go @@ -22,6 +22,7 @@ package zap import ( "encoding/json" + "errors" "fmt" "io" "net/http" @@ -108,7 +109,7 @@ func decodePutRequest(contentType string, r *http.Request) (zapcore.Level, error func decodePutURL(r *http.Request) (zapcore.Level, error) { lvl := r.FormValue("level") if lvl == "" { - return 0, fmt.Errorf("must specify logging level") + return 0, errors.New("must specify logging level") } var l zapcore.Level if err := l.UnmarshalText([]byte(lvl)); err != nil { @@ -125,7 +126,7 @@ func decodePutJSON(body io.Reader) (zapcore.Level, error) { return 0, fmt.Errorf("malformed request body: %v", err) } if pld.Level == nil { - return 0, fmt.Errorf("must specify logging level") + return 0, errors.New("must specify logging level") } return *pld.Level, nil