From: Josh Bleecher Snyder Date: Mon, 11 Jul 2016 19:30:45 +0000 (-0700) Subject: cmd/vet: clean up printing errors with no position X-Git-Tag: go1.8beta1~1733 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=0952a15cd17755c655910e4b2601d0f255d71c42;p=gostls13.git 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 TryBot-Result: Gobot Gobot Reviewed-by: Rob Pike --- diff --git a/src/cmd/vet/main.go b/src/cmd/vet/main.go index 4f3cca8f6d..81063856dd 100644 --- a/src/cmd/vet/main.go +++ b/src/cmd/vet/main.go @@ -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.