Skip to content

Commit

Permalink
lint - fix all errcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
atercattus committed Mar 28, 2021
1 parent 2bb9e96 commit c2eb6e7
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 25 deletions.
2 changes: 1 addition & 1 deletion canal/canal.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func (c *Canal) Close() {
c.conn = nil
c.connLock.Unlock()

c.eventHandler.OnPosSynced(c.master.Position(), c.master.GTIDSet(), true)
_ = c.eventHandler.OnPosSynced(c.master.Position(), c.master.GTIDSet(), true)
}

func (c *Canal) WaitDumpDone() <-chan struct{} {
Expand Down
2 changes: 1 addition & 1 deletion client/resp.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (c *Conn) handleAuthResult() error {
}
}
} else {
errors.Errorf("invalid packet")
return errors.Errorf("invalid packet %x", data[0])
}
} else if c.authPluginName == AUTH_SHA256_PASSWORD {
if len(data) == 0 {
Expand Down
9 changes: 6 additions & 3 deletions dump/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,10 @@ func (d *Dumper) Dump(w io.Writer) error {
// If we only dump some tables, the dump data will not have database name
// which makes us hard to parse, so here we add it manually.

w.Write([]byte(fmt.Sprintf("USE `%s`;\n", d.TableDB)))
_, err := w.Write([]byte(fmt.Sprintf("USE `%s`;\n", d.TableDB)))
if err != nil {
return fmt.Errorf(`could not write USE command: %w`, err)
}
}

log.Infof("exec mysqldump with %v", args)
Expand All @@ -251,12 +254,12 @@ func (d *Dumper) DumpAndParse(h ParseHandler) error {
done := make(chan error, 1)
go func() {
err := Parse(r, h, !d.masterDataSkipped)
r.CloseWithError(err)
_ = r.CloseWithError(err)
done <- err
}()

err := d.Dump(w)
w.CloseWithError(err)
_ = w.CloseWithError(err)

err = <-done

Expand Down
3 changes: 2 additions & 1 deletion dump/dump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ e7574090-b123-11e8-8bb4-005056a29643:1-12'
reader := strings.NewReader(tt.input)
var handler = new(testParseHandler)

Parse(reader, handler, true)
err := Parse(reader, handler, true)
c.Assert(err, IsNil)

if tt.expected == "" {
if handler.gset != nil {
Expand Down
10 changes: 5 additions & 5 deletions mysql/mysql_gtid.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,14 @@ func (s *UUIDSet) String() string {
}

func (s *UUIDSet) encode(w io.Writer) {
w.Write(s.SID.Bytes())
_, _ = w.Write(s.SID.Bytes())
n := int64(len(s.Intervals))

binary.Write(w, binary.LittleEndian, n)
_ = binary.Write(w, binary.LittleEndian, n)

for _, i := range s.Intervals {
binary.Write(w, binary.LittleEndian, i.Start)
binary.Write(w, binary.LittleEndian, i.Stop)
_ = binary.Write(w, binary.LittleEndian, i.Start)
_ = binary.Write(w, binary.LittleEndian, i.Stop)
}
}

Expand Down Expand Up @@ -448,7 +448,7 @@ func (s *MysqlGTIDSet) String() string {
func (s *MysqlGTIDSet) Encode() []byte {
var buf bytes.Buffer

binary.Write(&buf, binary.LittleEndian, uint64(len(s.Sets)))
_ = binary.Write(&buf, binary.LittleEndian, uint64(len(s.Sets)))

for i := range s.Sets {
s.Sets[i].encode(&buf)
Expand Down
3 changes: 2 additions & 1 deletion mysql/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ func (t *mysqlTestSuite) TestMysqlUpdate(c *check.C) {
g1, err := ParseMysqlGTIDSet("3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57")
c.Assert(err, check.IsNil)

g1.Update("3E11FA47-71CA-11E1-9E33-C80AA9429562:21-58")
err = g1.Update("3E11FA47-71CA-11E1-9E33-C80AA9429562:21-58")
c.Assert(err, check.IsNil)

c.Assert(strings.ToUpper(g1.String()), check.Equals, "3E11FA47-71CA-11E1-9E33-C80AA9429562:21-58")
}
Expand Down
10 changes: 8 additions & 2 deletions mysql/resultset_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,21 @@ func BuildSimpleTextResultset(names []string, values [][]interface{}) (*Resultse
}
if r.Fields[j] == nil {
r.Fields[j] = &Field{Name: hack.Slice(names[j]), Type: typ}
formatField(r.Fields[j], value)
err = formatField(r.Fields[j], value)
if err != nil {
return nil, errors.Trace(err)
}
} else if typ != r.Fields[j].Type {
// we got another type in the same column. in general, we treat it as an error, except
// the case, when old value was null, and the new one isn't null, so we can update
// type info for fields.
oldIsNull, newIsNull := r.Fields[j].Type == MYSQL_TYPE_NULL, typ == MYSQL_TYPE_NULL
if oldIsNull && !newIsNull { // old is null, new isn't, update type info.
r.Fields[j].Type = typ
formatField(r.Fields[j], value)
err = formatField(r.Fields[j], value)
if err != nil {
return nil, errors.Trace(err)
}
} else if !oldIsNull && !newIsNull { // different non-null types, that's an error.
return nil, errors.Errorf("row types aren't consistent")
}
Expand Down
4 changes: 3 additions & 1 deletion replication/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ func (b *BinlogSyncer) StartBackup(backupDir string, p Position, timeout time.Du
// Force use raw mode
b.parser.SetRawMode(true)

os.MkdirAll(backupDir, 0755)
if err := os.MkdirAll(backupDir, 0755); err != nil {
return errors.Trace(err)
}

s, err := b.StartSync(p)
if err != nil {
Expand Down
15 changes: 10 additions & 5 deletions replication/binlogsyncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,10 @@ func (b *BinlogSyncer) close() {
b.cancel()

if b.c != nil {
b.c.SetReadDeadline(time.Now().Add(100 * time.Millisecond))
err := b.c.SetReadDeadline(time.Now().Add(100 * time.Millisecond))
if err != nil {
log.Warnf(`could not set read deadline: %s`, err)
}
}

// kill last connection id
Expand Down Expand Up @@ -234,17 +237,19 @@ func (b *BinlogSyncer) registerSlave() error {
}

if len(b.cfg.Charset) != 0 {
b.c.SetCharset(b.cfg.Charset)
if err = b.c.SetCharset(b.cfg.Charset); err != nil {
return errors.Trace(err)
}
}

//set read timeout
if b.cfg.ReadTimeout > 0 {
b.c.SetReadDeadline(time.Now().Add(b.cfg.ReadTimeout))
_ = b.c.SetReadDeadline(time.Now().Add(b.cfg.ReadTimeout))
}

if b.cfg.RecvBufferSize > 0 {
if tcp, ok := b.c.Conn.Conn.(*net.TCPConn); ok {
tcp.SetReadBuffer(b.cfg.RecvBufferSize)
_ = tcp.SetReadBuffer(b.cfg.RecvBufferSize)
}
}

Expand Down Expand Up @@ -707,7 +712,7 @@ func (b *BinlogSyncer) onStream(s *BinlogStreamer) {

//set read timeout
if b.cfg.ReadTimeout > 0 {
b.c.SetReadDeadline(time.Now().Add(b.cfg.ReadTimeout))
_ = b.c.SetReadDeadline(time.Now().Add(b.cfg.ReadTimeout))
}

// Reset retry count on successful packet receieve
Expand Down
2 changes: 1 addition & 1 deletion replication/replication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ func (t *testSyncerSuite) testPositionSync(c *C) {

// Test re-sync.
time.Sleep(100 * time.Millisecond)
t.b.c.SetReadDeadline(time.Now().Add(time.Millisecond))
_ = t.b.c.SetReadDeadline(time.Now().Add(time.Millisecond))
time.Sleep(100 * time.Millisecond)

t.testSync(c, s)
Expand Down
8 changes: 6 additions & 2 deletions server/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,14 @@ func (c *Conn) dispatch(data []byte) interface{} {
return r
}
case COM_STMT_CLOSE:
c.handleStmtClose(data)
if err := c.handleStmtClose(data); err != nil {
return err
}
return noResponse{}
case COM_STMT_SEND_LONG_DATA:
c.handleStmtSendLongData(data)
if err := c.handleStmtSendLongData(data); err != nil {
return err
}
return noResponse{}
case COM_STMT_RESET:
if r, err := c.handleStmtReset(data); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion server/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (c *Conn) handshake() error {
if err == ErrAccessDenied {
err = NewDefaultError(ER_ACCESS_DENIED_ERROR, c.user, c.LocalAddr().String(), "Yes")
}
c.writeError(err)
_ = c.writeError(err)
return err
}

Expand Down
6 changes: 5 additions & 1 deletion server/example/server_example.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ func main() {
}

for {
conn.HandleCommand()
err = conn.HandleCommand()
if err != nil {
log.Errorf(`Could not handle command: %v`, err)
return
}
}
}()
}
Expand Down

0 comments on commit c2eb6e7

Please sign in to comment.