errors icon indicating copy to clipboard operation
errors copied to clipboard

Frame.Format %+s does not match documentation

Open thsnr opened this issue 7 years ago • 0 comments

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

  1. $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])
}
  1. 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.

thsnr avatar Aug 18 '18 09:08 thsnr