diff options
author | Josh Bleecher Snyder <josharian@gmail.com> | 2016-07-11 12:30:45 -0700 |
---|---|---|
committer | Josh Bleecher Snyder <josharian@gmail.com> | 2016-08-22 15:42:30 +0000 |
commit | 0952a15cd17755c655910e4b2601d0f255d71c42 (patch) | |
tree | c1b2850c53f26a444adea8d59494aa2d1f0831ff /src/cmd/vet/main.go | |
parent | 4af1148079f00b461c9ae79df22aa647aa7ff5ef (diff) | |
download | go-0952a15cd17755c655910e4b2601d0f255d71c42.tar.gz go-0952a15cd17755c655910e4b2601d0f255d71c42.zip |
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: Rob Pike <r@golang.org>
Diffstat (limited to 'src/cmd/vet/main.go')
-rw-r--r-- | src/cmd/vet/main.go | 12 |
1 files changed, 10 insertions, 2 deletions
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. |