Handle a bunch of unchecked errors (#4461)

There are many more (mostly finalizers like Close/Stop/etc.), but most of
the others seemed like one couldn't do much about them anyway.

Signed-off-by: Julius Volz <julius.volz@gmail.com>
This commit is contained in:
Julius Volz 2018-08-17 17:24:35 +02:00 committed by GitHub
parent d4eae8cc0c
commit 8fbe1b5133
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 47 additions and 15 deletions

View file

@ -16,6 +16,7 @@ package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"github.com/gogo/protobuf/proto"
@ -58,5 +59,5 @@ func main() {
}
})
http.ListenAndServe(":1234", nil)
log.Fatal(http.ListenAndServe(":1234", nil))
}

View file

@ -100,11 +100,16 @@ func main() {
http.Handle(cfg.telemetryPath, prometheus.Handler())
logLevel := promlog.AllowedLevel{}
logLevel.Set(cfg.logLevel)
if err := logLevel.Set(cfg.logLevel); err != nil {
panic(fmt.Sprintf("Error setting log level: %v", err))
}
logger := promlog.New(logLevel)
writers, readers := buildClients(logger, cfg)
serve(logger, cfg.listenAddr, writers, readers)
if err := serve(logger, cfg.listenAddr, writers, readers); err != nil {
level.Error(logger).Log("msg", "Failed to listen", "addr", cfg.listenAddr, "err", err)
os.Exit(1)
}
}
func parseFlags() *config {

View file

@ -433,7 +433,10 @@ func (t *Test) exec(tc testCommand) error {
}
case *evalCmd:
q, _ := t.queryEngine.NewInstantQuery(t.storage, cmd.expr, cmd.start)
q, err := t.queryEngine.NewInstantQuery(t.storage, cmd.expr, cmd.start)
if err != nil {
return err
}
res := q.Exec(t.context)
if res.Err != nil {
if cmd.fail {
@ -446,14 +449,17 @@ func (t *Test) exec(tc testCommand) error {
return fmt.Errorf("expected error evaluating query %q (line %d) but got none", cmd.expr, cmd.line)
}
err := cmd.compareResult(res.Value)
err = cmd.compareResult(res.Value)
if err != nil {
return fmt.Errorf("error in %s %s: %s", cmd, cmd.expr, err)
}
// Check query returns same result in range mode,
/// by checking against the middle step.
q, _ = t.queryEngine.NewRangeQuery(t.storage, cmd.expr, cmd.start.Add(-time.Minute), cmd.start.Add(time.Minute), time.Minute)
q, err = t.queryEngine.NewRangeQuery(t.storage, cmd.expr, cmd.start.Add(-time.Minute), cmd.start.Add(time.Minute), time.Minute)
if err != nil {
return err
}
rangeRes := q.Exec(t.context)
if rangeRes.Err != nil {
return fmt.Errorf("error evaluating query %q (line %d) in range mode: %s", cmd.expr, cmd.line, rangeRes.Err)

View file

@ -485,7 +485,10 @@ func (g *Group) RestoreForState(ts time.Time) {
smpl := alertRule.forStateSample(a, time.Now(), 0)
var matchers []*labels.Matcher
for _, l := range smpl.Metric {
mt, _ := labels.NewMatcher(labels.MatchEqual, l.Name, l.Value)
mt, err := labels.NewMatcher(labels.MatchEqual, l.Name, l.Value)
if err != nil {
panic(err)
}
matchers = append(matchers, mt)
}

View file

@ -482,7 +482,9 @@ func (s *targetScraper) scrape(ctx context.Context, w io.Writer) error {
}
} else {
s.buf.Reset(resp.Body)
s.gzipr.Reset(s.buf)
if err = s.gzipr.Reset(s.buf); err != nil {
return err
}
}
_, err = io.Copy(w, s.gzipr)
@ -813,7 +815,9 @@ mainLoop:
scrapeErr = appErr
}
sl.report(start, time.Since(start), total, added, scrapeErr)
if err := sl.report(start, time.Since(start), total, added, scrapeErr); err != nil {
level.Warn(sl.l).Log("msg", "appending scrape report failed", "err", err)
}
last = start
select {

View file

@ -29,11 +29,13 @@ func (s *Storage) Add(l labels.Labels, t int64, v float64) (uint64, error) {
s.mtx.RLock()
defer s.mtx.RUnlock()
for _, q := range s.queues {
q.Append(&model.Sample{
if err := q.Append(&model.Sample{
Metric: labelsToMetric(l),
Timestamp: model.Time(t),
Value: model.SampleValue(v),
})
}); err != nil {
panic(err) // QueueManager.Append() should always return nil as per doc string.
}
}
return 0, nil
}

View file

@ -380,7 +380,9 @@ var (
)
func (api *API) series(r *http.Request) (interface{}, *apiError, func()) {
r.ParseForm()
if err := r.ParseForm(); err != nil {
return nil, &apiError{errorBadData, fmt.Errorf("error parsing form values: %v", err)}, nil
}
if len(r.Form["match[]"]) == 0 {
return nil, &apiError{errorBadData, fmt.Errorf("no match[] parameter provided")}, nil
}
@ -816,7 +818,9 @@ func (api *API) deleteSeries(r *http.Request) (interface{}, *apiError, func()) {
return nil, &apiError{errorUnavailable, errors.New("TSDB not ready")}, nil
}
r.ParseForm()
if err := r.ParseForm(); err != nil {
return nil, &apiError{errorBadData, fmt.Errorf("error parsing form values: %v", err)}, nil
}
if len(r.Form["match[]"]) == 0 {
return nil, &apiError{errorBadData, fmt.Errorf("no match[] parameter provided")}, nil
}
@ -866,7 +870,10 @@ func (api *API) snapshot(r *http.Request) (interface{}, *apiError, func()) {
if !api.enableAdmin {
return nil, &apiError{errorUnavailable, errors.New("Admin APIs disabled")}, nil
}
skipHead, _ := strconv.ParseBool(r.FormValue("skip_head"))
skipHead, err := strconv.ParseBool(r.FormValue("skip_head"))
if err != nil {
return nil, &apiError{errorUnavailable, fmt.Errorf("unable to parse boolean 'skip_head' argument: %v", err)}, nil
}
db := api.db()
if db == nil {

View file

@ -14,6 +14,7 @@
package web
import (
"fmt"
"net/http"
"sort"
@ -42,7 +43,10 @@ func (h *Handler) federation(w http.ResponseWriter, req *http.Request) {
h.mtx.RLock()
defer h.mtx.RUnlock()
req.ParseForm()
if err := req.ParseForm(); err != nil {
http.Error(w, fmt.Sprintf("error parsing form values: %v", err), http.StatusBadRequest)
return
}
var matcherSets [][]*labels.Matcher
for _, s := range req.Form["match[]"] {