Skip to content
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

fmt: unexpected behaviour for missing verb #5508

Closed
ianlancetaylor opened this issue May 17, 2013 · 3 comments
Closed

fmt: unexpected behaviour for missing verb #5508

ianlancetaylor opened this issue May 17, 2013 · 3 comments
Assignees

Comments

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented May 17, 2013

Quoting from a separate bug report:

I didn't see what the defined behavior of the fmt.printf family of functions should be
to the format pair %_, where _ is any character not defined as a verb. (This happened as
a result of an unrelated error). Currently the code  in fmt/print.go, lines 1096-1100
assumes that whatever follows the '%' is a valid verb, and charges ahead. (This might be
what you want to do, but perhaps it should be documented, if so) In the example, text
generated by html/template was inadvertently handed to Fprintf, and gave the somewhat
unintuitive message as shown.

package main

import "fmt"

func main() {
   fmt.Println(fmt.Sprintf(".%2a%3a4.1%3a29"))
}

gives

.%a(MISSING)%a(MISSING)4.1%a(MISSING)29

This could be fixed by skipping over, and emitting the %_, or giving  %a(NOT-VERB)
@ianlancetaylor
Copy link
Contributor Author

@ianlancetaylor ianlancetaylor commented May 17, 2013

Comment 1:

Owner changed to @robpike.

@robpike
Copy link
Contributor

@robpike robpike commented May 18, 2013

Comment 2:

Labels changed: added priority-soon, removed priority-triage.

Status changed to Accepted.

@robpike
Copy link
Contributor

@robpike robpike commented May 20, 2013

Comment 3:

This is a confusing example (Println of Sprintf for some reason, and then no arguments,
so there are multiple things happening).  The error reported is mostly about missing
arguments, not bad format verbs, so the complaint is malformed. But let's take it at
face value with a proper example:
    fmt.Printf("%w\n", 3)
which gives
%!w(int=3)
That seems like a reasonable error message. You get the erroneous verb reported, and the
value is printed regardless. The provided example with arguments:
    fmt.Printf(".%2a%3a4.1%3a29\n", 3, 4, 5)
which gives
.%!a(int= 3)%!a(int=  4)4.1%!a(int=  5)29
I claim that's fine. Verbs in general cannot be outlawed, since a Formatter interface is
allowed to take any verb at all. We could check that a Formatter is being used and then
complain, but the way we complain wouldn't really be any different.
Working as intended.

Status changed to WorkingAsIntended.

@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.