diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2018-08-01 13:19:54 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2018-08-02 16:57:31 +0200 |
| commit | c67a9331a4f7c25df943ff821c9c6ed8013df869 (patch) | |
| tree | e380eb862ba4e10896ad0d31442bd2f2c4928c0e | |
| parent | 0a7cf4ec6374315af969a5bad7532095a1962492 (diff) | |
gometalinter: clean up some errcheck warnings
Check some errors where relevant.
Unfortunately enabling errcheck does not look feasible, too many warnings.
Update #538
| -rw-r--r-- | dashboard/app/api.go | 8 | ||||
| -rw-r--r-- | dashboard/app/jobs.go | 4 | ||||
| -rw-r--r-- | dashboard/app/reporting_email.go | 12 | ||||
| -rw-r--r-- | pkg/db/db.go | 8 | ||||
| -rw-r--r-- | pkg/host/host_linux.go | 17 | ||||
| -rw-r--r-- | pkg/rpctype/rpc.go | 24 | ||||
| -rw-r--r-- | vm/adb/adb.go | 38 |
7 files changed, 53 insertions, 58 deletions
diff --git a/dashboard/app/api.go b/dashboard/app/api.go index df13c022c..839f423ef 100644 --- a/dashboard/app/api.go +++ b/dashboard/app/api.go @@ -82,10 +82,14 @@ func handleJSON(fn JSONHandler) http.Handler { if strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") { w.Header().Set("Content-Encoding", "gzip") gz := gzip.NewWriter(w) - json.NewEncoder(gz).Encode(reply) + if err := json.NewEncoder(gz).Encode(reply); err != nil { + log.Errorf(c, "failed to encode reply: %v", err) + } gz.Close() } else { - json.NewEncoder(w).Encode(reply) + if err := json.NewEncoder(w).Encode(reply); err != nil { + log.Errorf(c, "failed to encode reply: %v", err) + } } }) } diff --git a/dashboard/app/jobs.go b/dashboard/app/jobs.go index b12c85776..4a2301af4 100644 --- a/dashboard/app/jobs.go +++ b/dashboard/app/jobs.go @@ -169,7 +169,9 @@ func addTestJob(c context.Context, bug *Bug, bugKey *datastore.Key, bugReporting } err = datastore.RunInTransaction(c, tx, &datastore.TransactionOptions{XG: true, Attempts: 30}) if patchID != 0 && deletePatch || err != nil { - datastore.Delete(c, datastore.NewKey(c, textPatch, "", patchID, nil)) + if err := datastore.Delete(c, datastore.NewKey(c, textPatch, "", patchID, nil)); err != nil { + log.Errorf(c, "failed to delete patch for dup job: %v", err) + } } if err != nil { return "", fmt.Errorf("job tx failed: %v", err) diff --git a/dashboard/app/reporting_email.go b/dashboard/app/reporting_email.go index de5855bc2..799820fb4 100644 --- a/dashboard/app/reporting_email.go +++ b/dashboard/app/reporting_email.go @@ -352,20 +352,26 @@ func loadBugInfo(c context.Context, msg *email.Email) (bug *Bug, bugReporting *B log.Infof(c, "no bug ID (%q)", msg.Subject) } else { log.Errorf(c, "no bug ID (%q)", msg.Subject) - replyTo(c, msg, "Can't find the corresponding bug.", nil) + if err := replyTo(c, msg, "Can't find the corresponding bug.", nil); err != nil { + log.Errorf(c, "failed to send reply: %v", err) + } } return nil, nil, nil } bug, _, err := findBugByReportingID(c, msg.BugID) if err != nil { log.Errorf(c, "can't find bug: %v", err) - replyTo(c, msg, "Can't find the corresponding bug.", nil) + if err := replyTo(c, msg, "Can't find the corresponding bug.", nil); err != nil { + log.Errorf(c, "failed to send reply: %v", err) + } return nil, nil, nil } bugReporting, _ = bugReportingByID(bug, msg.BugID) if bugReporting == nil { log.Errorf(c, "can't find bug reporting: %v", err) - replyTo(c, msg, "Can't find the corresponding bug.", nil) + if err := replyTo(c, msg, "Can't find the corresponding bug.", nil); err != nil { + log.Errorf(c, "failed to send reply: %v", err) + } return nil, nil, nil } reporting = config.Namespaces[bug.Namespace].ReportingByName(bugReporting.Name) diff --git a/pkg/db/db.go b/pkg/db/db.go index 4d48e1229..5c2755860 100644 --- a/pkg/db/db.go +++ b/pkg/db/db.go @@ -47,7 +47,9 @@ func Open(filename string) (*DB, error) { db.Version, db.Records, db.uncompacted = deserializeDB(bufio.NewReader(f)) f.Close() if len(db.Records) == 0 || db.uncompacted/10*9 > len(db.Records) { - db.compact() + if err := db.compact(); err != nil { + return nil, err + } } return db, nil } @@ -75,8 +77,7 @@ func (db *DB) Delete(key string) { func (db *DB) Flush() error { if db.uncompacted/10*9 > len(db.Records) { - db.compact() - return nil + return db.compact() } if db.pending == nil { return nil @@ -168,7 +169,6 @@ func serializeRecord(w *bytes.Buffer, key string, val []byte, seq uint64) { if _, err := fw.Write(val); err != nil { panic(err) } - fw.Flush() fw.Close() binary.Write(bytes.NewBuffer(w.Bytes()[lenPos:lenPos:lenPos+8]), binary.LittleEndian, uint32(len(w.Bytes())-startPos)) } diff --git a/pkg/host/host_linux.go b/pkg/host/host_linux.go index 38b2461f1..6d7c9c516 100644 --- a/pkg/host/host_linux.go +++ b/pkg/host/host_linux.go @@ -337,8 +337,8 @@ func checkCoverage() string { return "" } -func checkComparisons() string { - if reason := checkDebugFS(); reason != "" { +func checkComparisons() (reason string) { + if reason = checkDebugFS(); reason != "" { return reason } // TODO(dvyukov): this should run under target arch. @@ -365,7 +365,11 @@ func checkComparisons() string { if err != nil { return fmt.Sprintf("KCOV mmap failed: %v", err) } - defer syscall.Munmap(mem) + defer func() { + if err := syscall.Munmap(mem); err != nil { + reason = fmt.Sprintf("munmap failed: %v", err) + } + }() _, _, errno = syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), linux.KCOV_ENABLE, linux.KCOV_TRACE_CMP) if errno != 0 { @@ -374,7 +378,12 @@ func checkComparisons() string { } return fmt.Sprintf("ioctl(KCOV_TRACE_CMP) failed: %v", errno) } - defer syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), linux.KCOV_DISABLE, 0) + defer func() { + _, _, errno = syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), linux.KCOV_DISABLE, 0) + if errno != 0 { + reason = fmt.Sprintf("ioctl(KCOV_DISABLE) failed: %v", errno) + } + }() return "" } diff --git a/pkg/rpctype/rpc.go b/pkg/rpctype/rpc.go index 3838855a4..417a4f7b8 100644 --- a/pkg/rpctype/rpc.go +++ b/pkg/rpctype/rpc.go @@ -26,7 +26,9 @@ func NewRPCServer(addr string, receiver interface{}) (*RPCServer, error) { return nil, fmt.Errorf("failed to listen on %v: %v", addr, err) } s := rpc.NewServer() - s.Register(receiver) + if err := s.Register(receiver); err != nil { + return nil, err + } serv := &RPCServer{ ln: ln, s: s, @@ -41,8 +43,7 @@ func (serv *RPCServer) Serve() { log.Logf(0, "failed to accept an rpc connection: %v", err) continue } - conn.(*net.TCPConn).SetKeepAlive(true) - conn.(*net.TCPConn).SetKeepAlivePeriod(10 * time.Second) + setupKeepAlive(conn, 10*time.Second) go serv.s.ServeConn(newFlateConn(conn)) } } @@ -66,8 +67,7 @@ func Dial(addr string) (net.Conn, error) { if conn, err = net.DialTimeout("tcp", addr, 60*time.Second); err != nil { return nil, err } - conn.(*net.TCPConn).SetKeepAlive(true) - conn.(*net.TCPConn).SetKeepAlivePeriod(time.Minute) + setupKeepAlive(conn, time.Minute) return conn, nil } @@ -84,10 +84,11 @@ func NewRPCClient(addr string) (*RPCClient, error) { } func (cli *RPCClient) Call(method string, args, reply interface{}) error { - cli.conn.SetDeadline(time.Now().Add(5 * 60 * time.Second)) - err := cli.c.Call(method, args, reply) - cli.conn.SetDeadline(time.Time{}) - return err + if err := cli.conn.SetDeadline(time.Now().Add(5 * 60 * time.Second)); err != nil { + return err + } + defer cli.conn.SetDeadline(time.Time{}) + return cli.c.Call(method, args, reply) } func (cli *RPCClient) Close() { @@ -103,6 +104,11 @@ func RPCCall(addr, method string, args, reply interface{}) error { return c.Call(method, args, reply) } +func setupKeepAlive(conn net.Conn, keepAlive time.Duration) { + conn.(*net.TCPConn).SetKeepAlive(true) + conn.(*net.TCPConn).SetKeepAlivePeriod(keepAlive) +} + // flateConn wraps net.Conn in flate.Reader/Writer for compressed traffic. type flateConn struct { r io.ReadCloser diff --git a/vm/adb/adb.go b/vm/adb/adb.go index 88842d340..8a7a0bb2e 100644 --- a/vm/adb/adb.go +++ b/vm/adb/adb.go @@ -245,44 +245,12 @@ func (inst *instance) adb(args ...string) ([]byte, error) { if inst.debug { log.Logf(0, "executing adb %+v", args) } - rpipe, wpipe, err := os.Pipe() - if err != nil { - return nil, fmt.Errorf("failed to create pipe: %v", err) - } - defer wpipe.Close() - defer rpipe.Close() - cmd := osutil.Command(inst.adbBin, append([]string{"-s", inst.device}, args...)...) - cmd.Stdout = wpipe - cmd.Stderr = wpipe - if err := cmd.Start(); err != nil { - return nil, err - } - wpipe.Close() - done := make(chan bool) - go func() { - select { - case <-time.After(time.Minute): - if inst.debug { - log.Logf(0, "adb hanged") - } - cmd.Process.Kill() - case <-done: - } - }() - if err := cmd.Wait(); err != nil { - close(done) - out, _ := ioutil.ReadAll(rpipe) - if inst.debug { - log.Logf(0, "adb failed: %v\n%s", err, out) - } - return nil, fmt.Errorf("adb %+v failed: %v\n%s", args, err, out) - } - close(done) + args = append([]string{"-s", inst.device}, args...) + out, err := osutil.RunCmd(time.Minute, "", inst.adbBin, args...) if inst.debug { log.Logf(0, "adb returned") } - out, _ := ioutil.ReadAll(rpipe) - return out, nil + return out, err } func (inst *instance) repair() error { |
