mirror of
https://github.com/prometheus/alertmanager
synced 2024-12-25 15:42:18 +00:00
Merge pull request #1521 from mxinden/errcheck
*.go: Introduce errcheck enforcing error handling
This commit is contained in:
commit
b1a8fdd169
9
Makefile
9
Makefile
@ -15,6 +15,7 @@ include Makefile.common
|
||||
|
||||
FRONTEND_DIR = $(BIN_DIR)/ui/app
|
||||
DOCKER_IMAGE_NAME ?= alertmanager
|
||||
ERRCHECK_BINARY := $(FIRST_GOPATH)/bin/errcheck
|
||||
|
||||
ifdef DEBUG
|
||||
bindata_flags = -debug
|
||||
@ -59,3 +60,11 @@ clean:
|
||||
rm template/internal/deftmpl/bindata.go
|
||||
rm ui/bindata.go
|
||||
cd $(FRONTEND_DIR) && $(MAKE) clean
|
||||
|
||||
.PHONY: test
|
||||
test: common-test $(ERRCHECK_BINARY)
|
||||
@echo ">> running errcheck with exclude file scripts/errcheck_excludes.txt"
|
||||
$(ERRCHECK_BINARY) -verbose -exclude scripts/errcheck_excludes.txt -ignoretests ./...
|
||||
|
||||
$(ERRCHECK_BINARY):
|
||||
@go get github.com/kisielk/errcheck
|
||||
|
@ -770,7 +770,10 @@ func (api *API) respond(w http.ResponseWriter, data interface{}) {
|
||||
level.Error(api.logger).Log("msg", "Error marshalling JSON", "err", err)
|
||||
return
|
||||
}
|
||||
w.Write(b)
|
||||
|
||||
if _, err := w.Write(b); err != nil {
|
||||
level.Error(api.logger).Log("msg", "failed to write data to connection", "err", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (api *API) respondError(w http.ResponseWriter, apiErr apiError, data interface{}) {
|
||||
@ -796,7 +799,9 @@ func (api *API) respondError(w http.ResponseWriter, apiErr apiError, data interf
|
||||
}
|
||||
level.Error(api.logger).Log("msg", "API error", "err", apiErr.Error())
|
||||
|
||||
w.Write(b)
|
||||
if _, err := w.Write(b); err != nil {
|
||||
level.Error(api.logger).Log("msg", "failed to write data to connection", "err", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (api *API) receive(r *http.Request, v interface{}) error {
|
||||
|
@ -407,7 +407,8 @@ func main() {
|
||||
for {
|
||||
select {
|
||||
case <-hup:
|
||||
reload()
|
||||
// ignore error, already logged in `reload()`
|
||||
_ = reload()
|
||||
case errc := <-webReload:
|
||||
errc <- reload()
|
||||
}
|
||||
|
@ -280,7 +280,11 @@ func (n *Email) Notify(ctx context.Context, as ...*types.Alert) (bool, error) {
|
||||
return true, err
|
||||
}
|
||||
}
|
||||
defer c.Quit()
|
||||
defer func() {
|
||||
if err := c.Quit(); err != nil {
|
||||
level.Error(n.logger).Log("msg", "failed to close SMTP connection", "err", err)
|
||||
}
|
||||
}()
|
||||
|
||||
if n.conf.Hello != "" {
|
||||
err := c.Hello(n.conf.Hello)
|
||||
|
@ -90,9 +90,8 @@ func (a *Alerts) runGC() {
|
||||
}
|
||||
|
||||
// Close the alert provider.
|
||||
func (a *Alerts) Close() error {
|
||||
func (a *Alerts) Close() {
|
||||
close(a.stopGC)
|
||||
return nil
|
||||
}
|
||||
|
||||
func max(a, b int) int {
|
||||
|
8
scripts/errcheck_excludes.txt
Normal file
8
scripts/errcheck_excludes.txt
Normal file
@ -0,0 +1,8 @@
|
||||
(io.Closer).Close
|
||||
(*os.File).Close
|
||||
fmt.Fprintf
|
||||
fmt.Fprintln
|
||||
|
||||
(github.com/prometheus/alertmanager/vendor/github.com/go-kit/kit/log.Logger).Log
|
||||
// Allowed log levels are enforced via kingpin
|
||||
(*github.com/prometheus/alertmanager/vendor/github.com/prometheus/common/promlog.AllowedLevel).Set
|
@ -94,7 +94,11 @@ func freeAddress() string {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer l.Close()
|
||||
defer func() {
|
||||
if err := l.Close(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}()
|
||||
|
||||
return l.Addr().String()
|
||||
}
|
||||
|
@ -257,7 +257,11 @@ func NewWebhook(c *Collector) *MockWebhook {
|
||||
collector: c,
|
||||
opts: c.opts,
|
||||
}
|
||||
go http.Serve(l, wh)
|
||||
go func() {
|
||||
if err := http.Serve(l, wh); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}()
|
||||
|
||||
return wh
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user