Skip to content

Commit

Permalink
Fix issues reported by golangci-lint (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
dveeden authored Jan 22, 2024
1 parent 7a6770e commit d5f7166
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
11 changes: 7 additions & 4 deletions generate_perror/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func scanErrCodeFile(fileName string, nameToNum map[string]int) {
r := regexp.MustCompile(`^\s+(\w+)*\s+=\s+(\d+)$`)
for s.Scan() {
m := r.FindStringSubmatch(s.Text())
if m != nil && len(m) == 3 && m[1] != "" && m[2] != "" {
if len(m) == 3 && m[1] != "" && m[2] != "" {
i, err := strconv.Atoi(m[2])
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -134,7 +134,7 @@ func main() {
r := regexp.MustCompile(`^MySQL error code MY-0*(\d+) \((\w+)\)`)
for s.Scan() {
m := r.FindStringSubmatch(s.Text())
if m != nil && len(m) == 3 && m[1] != "" && m[2] != "" {
if len(m) == 3 && m[1] != "" && m[2] != "" {
c, err := strconv.Atoi(m[1])
if err != nil {
log.Fatal(err)
Expand All @@ -145,7 +145,10 @@ func main() {
checkNewErr(m[2], i, NameToNum)
}
}
cmd.Wait()
err = cmd.Wait()
if err != nil {
log.Fatal(err)
}
}
if maxError >= 1000 {
fmt.Printf("\r")
Expand All @@ -170,7 +173,7 @@ func main() {
sort.Slice(codes, func(i, j int) bool {
return codes[i].Code < codes[j].Code || codes[i].Code == codes[j].Code && codes[i].Name < codes[j].Name
})
for i, _ := range codes {
for i := range codes {
_, err = w.WriteString("\t\"" + codes[i].Name + `": ` + strconv.Itoa(codes[i].Code) + ",\n")
if err != nil {
log.Fatal(err)
Expand Down
10 changes: 8 additions & 2 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,10 @@ func (t *tester) preProcess() {

func (t *tester) postProcess() {
if !reserveSchema {
t.mdb.Exec(fmt.Sprintf("drop database `%s`", strings.ReplaceAll(t.name, "/", "__")))
_, err := t.mdb.Exec(fmt.Sprintf("drop database `%s`", strings.ReplaceAll(t.name, "/", "__")))
if err != nil {
log.Errorf("failed to drop database: %s", err.Error())
}
}
for _, v := range t.conn {
v.conn.Close()
Expand Down Expand Up @@ -918,13 +921,16 @@ func (t *tester) executeStmt(query string) error {
}

if t.enableInfo {
t.curr.conn.Raw(func(driverConn any) error {
err = t.curr.conn.Raw(func(driverConn any) error {
rowsAffected := driverConn.(*mysql.MysqlConn).RowsAffected()
lastMessage := driverConn.(*mysql.MysqlConn).LastMessage()
t.buf.WriteString(fmt.Sprintf("affected rows: %d\n", rowsAffected))
t.buf.WriteString(fmt.Sprintf("info: %s\n", lastMessage))
return nil
})
if err != nil {
log.Errorf("failed to get info: %s", err.Error())
}
}

if t.enableWarning {
Expand Down

0 comments on commit d5f7166

Please sign in to comment.