]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/vet: clean up printing errors with no position
authorJosh Bleecher Snyder <josharian@gmail.com>
Mon, 11 Jul 2016 19:30:45 +0000 (12:30 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Mon, 22 Aug 2016 15:42:30 +0000 (15:42 +0000)
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: Rob Pike <r@golang.org>
src/cmd/vet/main.go

index 4f3cca8f6dd765a8fcbf2ee86a6282e137c9d1df..81063856dd1f7cff06bfae8ea898c375aba31662 100644 (file)
@@ -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.