[tools] Add clarification in check printf message.

4 views
Skip to first unread message

Gopher Robot (Gerrit)

unread,
May 28, 2023, 8:09:18 PM5/28/23
to Zhe Dong, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Congratulations on opening your first change. Thank you for your contribution!

Next steps:
A maintainer will review your change and provide feedback. See
https://go.dev/doc/contribute#review for more info and tips to get your
patch through code review.

Most changes in the Go project go through a few rounds of revision. This can be
surprising to people new to the project. The careful, iterative review process
is our way of helping mentor contributors and ensuring that their contributions
have a lasting impact.

View Change

    To view, visit change 499015. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-MessageType: comment
    Gerrit-Project: tools
    Gerrit-Branch: master
    Gerrit-Change-Id: I123f155ba2601252771ced36fd32d3408abc8eac
    Gerrit-Change-Number: 499015
    Gerrit-PatchSet: 1
    Gerrit-Owner: Zhe Dong <don...@google.com>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-Comment-Date: Mon, 29 May 2023 00:09:14 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: No

    Ian Lance Taylor (Gerrit)

    unread,
    May 28, 2023, 11:48:52 PM5/28/23
    to Zhe Dong, goph...@pubsubhelper.golang.org, Ian Lance Taylor, triciu...@appspot.gserviceaccount.com, Gopher Robot, golang-co...@googlegroups.com

    Attention is currently required from: Zhe Dong.

    Patch set 2:Run-TryBot +1

    View Change

      To view, visit change 499015. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-MessageType: comment
      Gerrit-Project: tools
      Gerrit-Branch: master
      Gerrit-Change-Id: I123f155ba2601252771ced36fd32d3408abc8eac
      Gerrit-Change-Number: 499015
      Gerrit-PatchSet: 2
      Gerrit-Owner: Zhe Dong <don...@google.com>
      Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
      Gerrit-CC: Gopher Robot <go...@golang.org>
      Gerrit-Attention: Zhe Dong <don...@google.com>
      Gerrit-Comment-Date: Mon, 29 May 2023 03:48:49 +0000
      Gerrit-HasComments: No
      Gerrit-Has-Labels: Yes

      kokoro (Gerrit)

      unread,
      May 29, 2023, 12:00:08 AM5/29/23
      to Zhe Dong, goph...@pubsubhelper.golang.org, Gopher Robot, Ian Lance Taylor, triciu...@appspot.gserviceaccount.com, golang-co...@googlegroups.com

      Attention is currently required from: Zhe Dong.

      Kokoro presubmit build finished with status: SUCCESS
      Logs at: https://source.cloud.google.com/results/invocations/d6ce9ced-7775-4dd7-8347-948d874e58e2

      Patch set 2:gopls-CI +1

      View Change

        To view, visit change 499015. To unsubscribe, or for help writing mail filters, visit settings.

        Gerrit-MessageType: comment
        Gerrit-Project: tools
        Gerrit-Branch: master
        Gerrit-Change-Id: I123f155ba2601252771ced36fd32d3408abc8eac
        Gerrit-Change-Number: 499015
        Gerrit-PatchSet: 2
        Gerrit-Owner: Zhe Dong <don...@google.com>
        Gerrit-Reviewer: Gopher Robot <go...@golang.org>
        Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
        Gerrit-Reviewer: kokoro <noreply...@google.com>
        Gerrit-Comment-Date: Mon, 29 May 2023 04:00:04 +0000
        Gerrit-HasComments: No
        Gerrit-Has-Labels: Yes

        Zhe Dong (Gerrit)

        unread,
        May 29, 2023, 11:08:20 AM5/29/23
        to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

        Zhe Dong has uploaded this change for review.

        View Change

        Add clarification in check printf message.

        E.g.

        user code:
        `return "", fmt.Errorf("couldn't parse BUILD file %q: w", buildFile, err)`

        message:
        `fmt.Errorf call needs 1 arg but has 2 args`

        user thought process:
        I have exactly 3 arguments in this call! why the message is telling me I need 1 but supplying 2 ?

        Change-Id: I123f155ba2601252771ced36fd32d3408abc8eac
        ---
        M go/analysis/passes/printf/printf.go
        M go/analysis/passes/printf/testdata/src/a/a.go
        2 files changed, 8 insertions(+), 8 deletions(-)

        diff --git a/go/analysis/passes/printf/printf.go b/go/analysis/passes/printf/printf.go
        index b2b8c67..b9c0d98 100644
        --- a/go/analysis/passes/printf/printf.go
        +++ b/go/analysis/passes/printf/printf.go
        @@ -604,7 +604,7 @@
        if maxArgNum != len(call.Args) {
        expect := maxArgNum - firstArg
        numArgs := len(call.Args) - firstArg
        - pass.ReportRangef(call, "%s call needs %v but has %v", fn.FullName(), count(expect, "arg"), count(numArgs, "arg"))
        + pass.ReportRangef(call, "the formating directives in %s call take %v but %v were supplied", fn.FullName(), count(expect, "arg"), count(numArgs, "arg"))
        }
        }

        diff --git a/go/analysis/passes/printf/testdata/src/a/a.go b/go/analysis/passes/printf/testdata/src/a/a.go
        index 18b9e3b..cf76f2f 100644
        --- a/go/analysis/passes/printf/testdata/src/a/a.go
        +++ b/go/analysis/passes/printf/testdata/src/a/a.go
        @@ -155,13 +155,13 @@
        fmt.Println("%T", "hi") // want "fmt.Println call has possible Printf formatting directive %T"
        fmt.Println("%s"+" there", "hi") // want "fmt.Println call has possible Printf formatting directive %s"
        fmt.Println("0.0%") // correct (trailing % couldn't be a formatting directive)
        - fmt.Printf("%s", "hi", 3) // want "fmt.Printf call needs 1 arg but has 2 args"
        - _ = fmt.Sprintf("%"+("s"), "hi", 3) // want "fmt.Sprintf call needs 1 arg but has 2 args"
        + fmt.Printf("%s", "hi", 3) // want "the formating directives in fmt.Printf call take 1 arg but 2 args were supplied"
        + _ = fmt.Sprintf("%"+("s"), "hi", 3) // want "the formating directives in fmt.Sprintf call take 1 arg but 2 args were supplied"
        fmt.Printf("%s%%%d", "hi", 3) // correct
        fmt.Printf("%08s", "woo") // correct
        fmt.Printf("% 8s", "woo") // correct
        fmt.Printf("%.*d", 3, 3) // correct
        - fmt.Printf("%.*d x", 3, 3, 3, 3) // want "fmt.Printf call needs 2 args but has 4 args"
        + fmt.Printf("%.*d x", 3, 3, 3, 3) // want "the formating directives in fmt.Printf call take 2 args but 4 args were supplied"
        fmt.Printf("%.*d x", "hi", 3) // want `fmt.Printf format %.*d uses non-int "hi" as argument of \*`
        fmt.Printf("%.*d x", i, 3) // correct
        fmt.Printf("%.*d x", s, 3) // want `fmt.Printf format %.\*d uses non-int s as argument of \*`
        @@ -178,19 +178,19 @@
        Printf("%s %d %.3v %q", "str", 4) // want "a.Printf format %.3v reads arg #3, but call has 2 args"
        f := new(ptrStringer)
        f.Warn(0, "%s", "hello", 3) // want `\(\*a.ptrStringer\).Warn call has possible Printf formatting directive %s`
        - f.Warnf(0, "%s", "hello", 3) // want `\(\*a.ptrStringer\).Warnf call needs 1 arg but has 2 args`
        + f.Warnf(0, "%s", "hello", 3) // want `the formating directives in \(\*a.ptrStringer\).Warnf call take 1 arg but 2 args were supplied`
        f.Warnf(0, "%r", "hello") // want `\(\*a.ptrStringer\).Warnf format %r has unknown verb r`
        f.Warnf(0, "%#s", "hello") // want `\(\*a.ptrStringer\).Warnf format %#s has unrecognized flag #`
        f.Warn2(0, "%s", "hello", 3) // want `\(\*a.ptrStringer\).Warn2 call has possible Printf formatting directive %s`
        - f.Warnf2(0, "%s", "hello", 3) // want `\(\*a.ptrStringer\).Warnf2 call needs 1 arg but has 2 args`
        + f.Warnf2(0, "%s", "hello", 3) // want `the formating directives in \(\*a.ptrStringer\).Warnf2 call take 1 arg but 2 args were supplied`
        f.Warnf2(0, "%r", "hello") // want `\(\*a.ptrStringer\).Warnf2 format %r has unknown verb r`
        f.Warnf2(0, "%#s", "hello") // want `\(\*a.ptrStringer\).Warnf2 format %#s has unrecognized flag #`
        f.Wrap(0, "%s", "hello", 3) // want `\(\*a.ptrStringer\).Wrap call has possible Printf formatting directive %s`
        - f.Wrapf(0, "%s", "hello", 3) // want `\(\*a.ptrStringer\).Wrapf call needs 1 arg but has 2 args`
        + f.Wrapf(0, "%s", "hello", 3) // want `the formating directives in \(\*a.ptrStringer\).Wrapf call take 1 arg but 2 args were supplied`
        f.Wrapf(0, "%r", "hello") // want `\(\*a.ptrStringer\).Wrapf format %r has unknown verb r`
        f.Wrapf(0, "%#s", "hello") // want `\(\*a.ptrStringer\).Wrapf format %#s has unrecognized flag #`
        f.Wrap2(0, "%s", "hello", 3) // want `\(\*a.ptrStringer\).Wrap2 call has possible Printf formatting directive %s`
        - f.Wrapf2(0, "%s", "hello", 3) // want `\(\*a.ptrStringer\).Wrapf2 call needs 1 arg but has 2 args`
        + f.Wrapf2(0, "%s", "hello", 3) // want `the formating directives in \(\*a.ptrStringer\).Wrapf2 call take 1 arg but 2 args were supplied`
        f.Wrapf2(0, "%r", "hello") // want `\(\*a.ptrStringer\).Wrapf2 format %r has unknown verb r`
        f.Wrapf2(0, "%#s", "hello") // want `\(\*a.ptrStringer\).Wrapf2 format %#s has unrecognized flag #`
        fmt.Printf("%#s", FormatterVal(true)) // correct (the type is responsible for formatting)

        To view, visit change 499015. To unsubscribe, or for help writing mail filters, visit settings.

        Gerrit-MessageType: newchange
        Gerrit-Project: tools
        Gerrit-Branch: master
        Gerrit-Change-Id: I123f155ba2601252771ced36fd32d3408abc8eac
        Gerrit-Change-Number: 499015

        Zhe Dong (Gerrit)

        unread,
        May 29, 2023, 11:08:20 AM5/29/23
        to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

        Attention is currently required from: Zhe Dong.

        Zhe Dong uploaded patch set #2 to this change.

        View Change

        Add clarification in check printf message.

        E.g.

        user code:
        `return "", fmt.Errorf("couldn't parse BUILD file %q: w", buildFile, err)`

        message:
        `fmt.Errorf call needs 1 arg but has 2 args`

        user thought process:
        I have exactly 3 arguments in this call! why the message is telling me I need 1 but supplying 2 ?

        Change-Id: I123f155ba2601252771ced36fd32d3408abc8eac
        ---
        M go/analysis/passes/printf/printf.go
        M go/analysis/passes/printf/testdata/src/a/a.go
        2 files changed, 8 insertions(+), 8 deletions(-)

        To view, visit change 499015. To unsubscribe, or for help writing mail filters, visit settings.

        Gerrit-MessageType: newpatchset
        Gerrit-Project: tools
        Gerrit-Branch: master
        Gerrit-Change-Id: I123f155ba2601252771ced36fd32d3408abc8eac
        Gerrit-Change-Number: 499015
        Gerrit-PatchSet: 2
        Gerrit-Owner: Zhe Dong <don...@google.com>
        Gerrit-CC: Gopher Robot <go...@golang.org>
        Reply all
        Reply to author
        Forward
        0 new messages