Skip to content

Commit c2eb6e7

Browse files
committed
lint - fix all errcheck
1 parent 2bb9e96 commit c2eb6e7

13 files changed

+51
-25
lines changed

canal/canal.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ func (c *Canal) Close() {
249249
c.conn = nil
250250
c.connLock.Unlock()
251251

252-
c.eventHandler.OnPosSynced(c.master.Position(), c.master.GTIDSet(), true)
252+
_ = c.eventHandler.OnPosSynced(c.master.Position(), c.master.GTIDSet(), true)
253253
}
254254

255255
func (c *Canal) WaitDumpDone() <-chan struct{} {

client/resp.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func (c *Conn) handleAuthResult() error {
142142
}
143143
}
144144
} else {
145-
errors.Errorf("invalid packet")
145+
return errors.Errorf("invalid packet %x", data[0])
146146
}
147147
} else if c.authPluginName == AUTH_SHA256_PASSWORD {
148148
if len(data) == 0 {

dump/dump.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,10 @@ func (d *Dumper) Dump(w io.Writer) error {
232232
// If we only dump some tables, the dump data will not have database name
233233
// which makes us hard to parse, so here we add it manually.
234234

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

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

258261
err := d.Dump(w)
259-
w.CloseWithError(err)
262+
_ = w.CloseWithError(err)
260263

261264
err = <-done
262265

dump/dump_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ e7574090-b123-11e8-8bb4-005056a29643:1-12'
180180
reader := strings.NewReader(tt.input)
181181
var handler = new(testParseHandler)
182182

183-
Parse(reader, handler, true)
183+
err := Parse(reader, handler, true)
184+
c.Assert(err, IsNil)
184185

185186
if tt.expected == "" {
186187
if handler.gset != nil {

mysql/mysql_gtid.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,14 @@ func (s *UUIDSet) String() string {
232232
}
233233

234234
func (s *UUIDSet) encode(w io.Writer) {
235-
w.Write(s.SID.Bytes())
235+
_, _ = w.Write(s.SID.Bytes())
236236
n := int64(len(s.Intervals))
237237

238-
binary.Write(w, binary.LittleEndian, n)
238+
_ = binary.Write(w, binary.LittleEndian, n)
239239

240240
for _, i := range s.Intervals {
241-
binary.Write(w, binary.LittleEndian, i.Start)
242-
binary.Write(w, binary.LittleEndian, i.Stop)
241+
_ = binary.Write(w, binary.LittleEndian, i.Start)
242+
_ = binary.Write(w, binary.LittleEndian, i.Stop)
243243
}
244244
}
245245

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

451-
binary.Write(&buf, binary.LittleEndian, uint64(len(s.Sets)))
451+
_ = binary.Write(&buf, binary.LittleEndian, uint64(len(s.Sets)))
452452

453453
for i := range s.Sets {
454454
s.Sets[i].encode(&buf)

mysql/mysql_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ func (t *mysqlTestSuite) TestMysqlUpdate(c *check.C) {
102102
g1, err := ParseMysqlGTIDSet("3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57")
103103
c.Assert(err, check.IsNil)
104104

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

107108
c.Assert(strings.ToUpper(g1.String()), check.Equals, "3E11FA47-71CA-11E1-9E33-C80AA9429562:21-58")
108109
}

mysql/resultset_helper.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,21 @@ func BuildSimpleTextResultset(names []string, values [][]interface{}) (*Resultse
146146
}
147147
if r.Fields[j] == nil {
148148
r.Fields[j] = &Field{Name: hack.Slice(names[j]), Type: typ}
149-
formatField(r.Fields[j], value)
149+
err = formatField(r.Fields[j], value)
150+
if err != nil {
151+
return nil, errors.Trace(err)
152+
}
150153
} else if typ != r.Fields[j].Type {
151154
// we got another type in the same column. in general, we treat it as an error, except
152155
// the case, when old value was null, and the new one isn't null, so we can update
153156
// type info for fields.
154157
oldIsNull, newIsNull := r.Fields[j].Type == MYSQL_TYPE_NULL, typ == MYSQL_TYPE_NULL
155158
if oldIsNull && !newIsNull { // old is null, new isn't, update type info.
156159
r.Fields[j].Type = typ
157-
formatField(r.Fields[j], value)
160+
err = formatField(r.Fields[j], value)
161+
if err != nil {
162+
return nil, errors.Trace(err)
163+
}
158164
} else if !oldIsNull && !newIsNull { // different non-null types, that's an error.
159165
return nil, errors.Errorf("row types aren't consistent")
160166
}

replication/backup.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ func (b *BinlogSyncer) StartBackup(backupDir string, p Position, timeout time.Du
2222
// Force use raw mode
2323
b.parser.SetRawMode(true)
2424

25-
os.MkdirAll(backupDir, 0755)
25+
if err := os.MkdirAll(backupDir, 0755); err != nil {
26+
return errors.Trace(err)
27+
}
2628

2729
s, err := b.StartSync(p)
2830
if err != nil {

replication/binlogsyncer.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,10 @@ func (b *BinlogSyncer) close() {
183183
b.cancel()
184184

185185
if b.c != nil {
186-
b.c.SetReadDeadline(time.Now().Add(100 * time.Millisecond))
186+
err := b.c.SetReadDeadline(time.Now().Add(100 * time.Millisecond))
187+
if err != nil {
188+
log.Warnf(`could not set read deadline: %s`, err)
189+
}
187190
}
188191

189192
// kill last connection id
@@ -234,17 +237,19 @@ func (b *BinlogSyncer) registerSlave() error {
234237
}
235238

236239
if len(b.cfg.Charset) != 0 {
237-
b.c.SetCharset(b.cfg.Charset)
240+
if err = b.c.SetCharset(b.cfg.Charset); err != nil {
241+
return errors.Trace(err)
242+
}
238243
}
239244

240245
//set read timeout
241246
if b.cfg.ReadTimeout > 0 {
242-
b.c.SetReadDeadline(time.Now().Add(b.cfg.ReadTimeout))
247+
_ = b.c.SetReadDeadline(time.Now().Add(b.cfg.ReadTimeout))
243248
}
244249

245250
if b.cfg.RecvBufferSize > 0 {
246251
if tcp, ok := b.c.Conn.Conn.(*net.TCPConn); ok {
247-
tcp.SetReadBuffer(b.cfg.RecvBufferSize)
252+
_ = tcp.SetReadBuffer(b.cfg.RecvBufferSize)
248253
}
249254
}
250255

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

708713
//set read timeout
709714
if b.cfg.ReadTimeout > 0 {
710-
b.c.SetReadDeadline(time.Now().Add(b.cfg.ReadTimeout))
715+
_ = b.c.SetReadDeadline(time.Now().Add(b.cfg.ReadTimeout))
711716
}
712717

713718
// Reset retry count on successful packet receieve

replication/replication_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ func (t *testSyncerSuite) testPositionSync(c *C) {
309309

310310
// Test re-sync.
311311
time.Sleep(100 * time.Millisecond)
312-
t.b.c.SetReadDeadline(time.Now().Add(time.Millisecond))
312+
_ = t.b.c.SetReadDeadline(time.Now().Add(time.Millisecond))
313313
time.Sleep(100 * time.Millisecond)
314314

315315
t.testSync(c, s)

server/command.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,14 @@ func (c *Conn) dispatch(data []byte) interface{} {
110110
return r
111111
}
112112
case COM_STMT_CLOSE:
113-
c.handleStmtClose(data)
113+
if err := c.handleStmtClose(data); err != nil {
114+
return err
115+
}
114116
return noResponse{}
115117
case COM_STMT_SEND_LONG_DATA:
116-
c.handleStmtSendLongData(data)
118+
if err := c.handleStmtSendLongData(data); err != nil {
119+
return err
120+
}
117121
return noResponse{}
118122
case COM_STMT_RESET:
119123
if r, err := c.handleStmtReset(data); err != nil {

server/conn.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func (c *Conn) handshake() error {
107107
if err == ErrAccessDenied {
108108
err = NewDefaultError(ER_ACCESS_DENIED_ERROR, c.user, c.LocalAddr().String(), "Yes")
109109
}
110-
c.writeError(err)
110+
_ = c.writeError(err)
111111
return err
112112
}
113113

server/example/server_example.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ func main() {
4444
}
4545

4646
for {
47-
conn.HandleCommand()
47+
err = conn.HandleCommand()
48+
if err != nil {
49+
log.Errorf(`Could not handle command: %v`, err)
50+
return
51+
}
4852
}
4953
}()
5054
}

0 commit comments

Comments
 (0)