errors
errors copied to clipboard
Frame.Format %+s does not match documentation
Description
The documentation of Frame.Format promises:
// %+s function name and path of source file relative to the compile time
// GOPATH separated by \n\t (<funcname>\n\t<path>)
// %+v equivalent to %+s:%d
However the absolute path is printed, not relative to GOPATH. This maches what is documented in StackTrace.Format:
// %+v Prints filename, function, and line number for each Frame in the stack.
Note no mention of being relative to GOPATH.
Go version: go version go1.10.3 linux/amd64
Steps to reproduce
-
$GOPATH/src/frame/main.go:
package main
import (
"fmt"
"github.com/pkg/errors"
)
type stackTracer interface {
StackTrace() errors.StackTrace
}
func main() {
fmt.Printf("%+s\n", errors.New("frame").(stackTracer).StackTrace()[0])
}
-
go run main.go
Expected output
main.main
src/frame/main.go
Actual results
With GOPATH=/tmp/gopath:
main.main
/tmp/gopath/src/frame/main.go
Proposed solution
Change the documentation of Frame.Format to be consistent with StackTrace.Format. If instead %+s is implemented to be relative to GOPATH, then update the documentation of StackTrace.Format. However note that out-of-GOPATH builds are coming in Go 1.11.