Commit 0952a15c authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

cmd/vet: clean up printing errors with no position

Before:

: runtime/asm_amd64.s:345: [amd64] morestack: use of 8(SP) points beyond argument frame

After:

runtime/asm_amd64.s:345: [amd64] morestack: use of 8(SP) points beyond argument frame

Updates #11041

Change-Id: Ic87a6d1a2a7b2a8bf737407bc981b159825c84f2
Reviewed-on: https://go-review.googlesource.com/27152
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarRob Pike <r@golang.org>
parent 4af11480
......@@ -440,14 +440,22 @@ func (f *File) loc(pos token.Pos) string {
return fmt.Sprintf("%s:%d", posn.Filename, posn.Line)
}
// locPrefix returns a formatted representation of the position for use as a line prefix.
func (f *File) locPrefix(pos token.Pos) string {
if pos == token.NoPos {
return ""
}
return fmt.Sprintf("%s: ", f.loc(pos))
}
// Warn reports an error but does not set the exit code.
func (f *File) Warn(pos token.Pos, args ...interface{}) {
fmt.Fprintf(os.Stderr, "%s: %s", f.loc(pos), fmt.Sprintln(args...))
fmt.Fprintf(os.Stderr, "%s%s", f.locPrefix(pos), fmt.Sprintln(args...))
}
// Warnf reports a formatted error but does not set the exit code.
func (f *File) Warnf(pos token.Pos, format string, args ...interface{}) {
fmt.Fprintf(os.Stderr, "%s: %s\n", f.loc(pos), fmt.Sprintf(format, args...))
fmt.Fprintf(os.Stderr, "%s%s\n", f.locPrefix(pos), fmt.Sprintf(format, args...))
}
// walkFile walks the file's tree.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment