-
Notifications
You must be signed in to change notification settings - Fork 18k
x/tools/go/analysis/printf: doc: explain "possible formatting directive" message in documentation #66733
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Print call has Printf formatting directive. |
Do you mean that you would prefer the message to say even less than it does currently, by removing the "possible" qualifier? |
It would be good to keep the message short. Let's work on making the documentation link that accompanies this message do a better job of calling out the mistake. |
OK, I'll treat this as a documentation problem and update the printf docs. |
Change https://go.dev/cl/578035 mentions this issue: |
See also #47872. |
...and, somewhat related, https://go.dev/cl/422854, derived from the google internal b/227741360. While the printf analyzer is among the most useful vet checks, it does tend to be confusing for new users. |
As someone who ran into difficulty with this message, the improvement that would help most (either in the message or the linked documentation) is a reminder that the caller probably meant to call a different function - the one that takes a formatting string instead of the one that doesn't, e.g. "Print call has Printf formatting directive. Call Printf instead of Print". |
The printf checker reports a diagnostic for calls like this:
(Aside: though it's easy to conceive of false positives for this heuristic, in practice it seems to be very reliable.)
In Google issue 302359716, a number of users tell us that the message makes them think the problem is in the format string, when really it's in the choice of formatting function. Perhaps the error message could give them a hint:
The error message could vary depending on whether the corresponding 'f' variant function exists. The main challenge is deciding the exact wording; these messages have been agonized over for a decade.
@robpike
The text was updated successfully, but these errors were encountered: