Skip to content

Use errors.New for preformatted error messages - #357

Open
cl2t wants to merge 1 commit into
DATA-DOG:masterfrom
cl2t:fix-preformatted-errors
Open

Use errors.New for preformatted error messages#357
cl2t wants to merge 1 commit into
DATA-DOG:masterfrom
cl2t:fix-preformatted-errors

Conversation

@cl2t

@cl2t cl2t commented Sep 11, 2026

Copy link
Copy Markdown

Go 1.27's printf analyzer reports non-constant format strings for the fmt.Errorf(msg) calls in sqlmock.go when building in GOPATH mode. These messages are already constructed from fixed strings and need no formatting.

Use errors.New(msg) for those calls and the matching Ping case. Error messages and the public API remain unchanged; no new dependency or Go version requirement is introduced.

Validation:

  • go vet and the existing race/coverage test suite pass on Go 1.26.3.
  • Go 1.27 GOPATH tests pass with vet enabled and -race. The integration run also covered the examples using the separately fixed sqlstruct dependency.

Assisted-by: Codex:GPT-6

The unexpected-call messages are already assembled strings. Construct
their errors directly instead of passing non-constant formats to Errorf.
This preserves the messages and avoids printf analyzer diagnostics in
recent Go GOPATH builds.

Signed-off-by: cl2t <yihong.or@isrc.iscas.ac.cn>
@cl2t
cl2t force-pushed the fix-preformatted-errors branch from 81daeb4 to 9ddad4a Compare September 14, 2026 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant