Skip to content

Commit 0952a15

Browse files
committed
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Rob Pike <[email protected]>
1 parent 4af1148 commit 0952a15

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/cmd/vet/main.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,14 +440,22 @@ func (f *File) loc(pos token.Pos) string {
440440
return fmt.Sprintf("%s:%d", posn.Filename, posn.Line)
441441
}
442442

443+
// locPrefix returns a formatted representation of the position for use as a line prefix.
444+
func (f *File) locPrefix(pos token.Pos) string {
445+
if pos == token.NoPos {
446+
return ""
447+
}
448+
return fmt.Sprintf("%s: ", f.loc(pos))
449+
}
450+
443451
// Warn reports an error but does not set the exit code.
444452
func (f *File) Warn(pos token.Pos, args ...interface{}) {
445-
fmt.Fprintf(os.Stderr, "%s: %s", f.loc(pos), fmt.Sprintln(args...))
453+
fmt.Fprintf(os.Stderr, "%s%s", f.locPrefix(pos), fmt.Sprintln(args...))
446454
}
447455

448456
// Warnf reports a formatted error but does not set the exit code.
449457
func (f *File) Warnf(pos token.Pos, format string, args ...interface{}) {
450-
fmt.Fprintf(os.Stderr, "%s: %s\n", f.loc(pos), fmt.Sprintf(format, args...))
458+
fmt.Fprintf(os.Stderr, "%s%s\n", f.locPrefix(pos), fmt.Sprintf(format, args...))
451459
}
452460

453461
// walkFile walks the file's tree.

0 commit comments

Comments
 (0)