From 742ad26b121926bcf0511877ec74af0551eafb51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Fri, 22 Nov 2024 17:09:15 +0100 Subject: [PATCH] Fix non-constant format strings ``` $ make GO=gotip build gotip version go version devel go1.24-4865aadc Fri Nov 22 05:22:24 2024 +0000 linux/amd64 gofmt (simplify) vet dump_region/main.go:59:14: non-constant format string in call to fmt.Printf pkg/check/privilege.go:146:51: non-constant format string in call to github.com/pingcap/tidb-tools/pkg/check.NewError pkg/check/table_structure.go:130:19: non-constant format string in call to github.com/pingcap/tidb-tools/pkg/check.NewError pkg/check/table_structure.go:136:19: non-constant format string in call to github.com/pingcap/tidb-tools/pkg/check.NewError importer/config.go:73:14: non-constant format string in call to fmt.Printf make: *** [Makefile:86: check] Error 1 ``` Related: https://github.com/golang/go/issues/60529 --- dump_region/main.go | 2 +- importer/config.go | 2 +- pkg/check/privilege.go | 6 +++++- pkg/check/table_structure.go | 4 ++-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/dump_region/main.go b/dump_region/main.go index 9fd0b29cd..b0c7a2584 100644 --- a/dump_region/main.go +++ b/dump_region/main.go @@ -56,7 +56,7 @@ type keyRange struct { func main() { flag.Parse() if *printVersion { - fmt.Printf(utils.GetRawInfo("dump_region")) + fmt.Println(utils.GetRawInfo("dump_region")) return } diff --git a/importer/config.go b/importer/config.go index 860c05ed3..ee76a839f 100644 --- a/importer/config.go +++ b/importer/config.go @@ -70,7 +70,7 @@ func (c *Config) Parse(arguments []string) error { } if c.printVersion { - fmt.Printf(utils.GetRawInfo("importer")) + fmt.Println(utils.GetRawInfo("importer")) return flag.ErrHelp } diff --git a/pkg/check/privilege.go b/pkg/check/privilege.go index ad670c1ee..3ec9fb48e 100644 --- a/pkg/check/privilege.go +++ b/pkg/check/privilege.go @@ -143,7 +143,11 @@ func verifyPrivileges(result *Result, grants []string, expectedGrants map[mysql. // get username and hostname node, err := parser.New().ParseOneStmt(grant, "", "") if err != nil { - result.Errors = append(result.Errors, NewError(errors.Annotatef(err, "grant %s, grant after replace %s", grants[i], grant).Error())) + result.Errors = append(result.Errors, + NewError("%s", + errors.Annotatef(err, "grant %s, grant after replace %s", grants[i], grant).Error(), + ), + ) return } grantStmt, ok := node.(*ast.GrantStmt) diff --git a/pkg/check/table_structure.go b/pkg/check/table_structure.go index bccf77e4e..0b9907c4d 100644 --- a/pkg/check/table_structure.go +++ b/pkg/check/table_structure.go @@ -127,13 +127,13 @@ func (c *TablesChecker) Check(ctx context.Context) *Result { if len(r.State) == 0 { r.State = StateWarning } - e := NewError(tableMsg + option.errMessage) + e := NewError("%s", tableMsg+option.errMessage) e.Severity = StateWarning e.Instruction = option.instruction r.Errors = append(r.Errors, e) case StateFailure: r.State = StateFailure - e := NewError(tableMsg + option.errMessage) + e := NewError("%s", tableMsg+option.errMessage) e.Instruction = option.instruction r.Errors = append(r.Errors, e) }