GithubHelp home page GithubHelp logo

Comments (6)

judwhite avatar judwhite commented on July 19, 2024

@davecheney @ChrisHines Playing with this a little more I noticed go vet complains about %n (and %#s).

What do you think about exposing these values as methods on Frame with stronger guarantees than Format?

from errors.

davecheney avatar davecheney commented on July 19, 2024

This commit was merged 6 months ago; might break people to change it now. Would you accept a PR to put the previous behavior under %#s and an update to the documentation?

It's probably too late to change the behaviour at this point. It'd be safer to document what exists now unless it's egregiously inconsistent.

from errors.

judwhite avatar judwhite commented on July 19, 2024
// Format accepts flags that alter the printing of some verbs, as follows:
//
//    %+s   path of source file relative to the compile time GOPATH
//    %+v   equivalent to %+s:%d

Current (248dadf):

func TestWrappedError(t *testing.T) {
	err := a()
	if st, ok := err.(stackTracer); ok {
		for _, frame := range st.StackTrace() {
			fmt.Printf("%+v\n", frame)
		}
	}
}

func a() error { return b() }
func b() error { return c() }
func c() error { return errors.Wrap(io.EOF, "unexpected eof") }
github.com/judwhite/httplog.c
        C:/Projects/go/src/github.com/judwhite/httplog/fallbackLogger_test.go:28
github.com/judwhite/httplog.b
        C:/Projects/go/src/github.com/judwhite/httplog/fallbackLogger_test.go:27
github.com/judwhite/httplog.a
        C:/Projects/go/src/github.com/judwhite/httplog/fallbackLogger_test.go:26
github.com/judwhite/httplog.TestWrappedError
        C:/Projects/go/src/github.com/judwhite/httplog/fallbackLogger_test.go:18
testing.tRunner
        C:/Go/src/testing/testing.go:610
runtime.goexit
        C:/Go/src/runtime/asm_amd64.s:2086

Previous (d4b5735):

github.com/judwhite/httplog/fallbackLogger_test.go:30
github.com/judwhite/httplog/fallbackLogger_test.go:29
github.com/judwhite/httplog/fallbackLogger_test.go:28
github.com/judwhite/httplog/fallbackLogger_test.go:18
testing/testing.go:610
runtime/asm_amd64.s:2086

from errors.

judwhite avatar judwhite commented on July 19, 2024

I would be happy with a change like this:

// File returns the path of the source file relative to the compile time GOPATH.
func (f Frame) File() string {
	pc := f.pc()
	fn := runtime.FuncForPC(pc)
	if fn == nil {
		return "unknown"
	}
	file, _ := fn.FileLine(pc)
	return trimGOPATH(fn.Name(), file)
}

// Func returns the function name.
func (f Frame) Func() string {
	name := runtime.FuncForPC(f.pc()).Name()
	return funcname(name)
}

// Line returns the source line.
func (f Frame) Line() int {
	return f.line()
}

If you're okay with this I'll submit a PR. The goal is to provide the user more control over stack trace formatting.

from errors.

ChrisHines avatar ChrisHines commented on July 19, 2024

Don't forget about #38. For reference see https://godoc.org/github.com/go-stack/stack#Call.Format and the code behind it.

from errors.

judwhite avatar judwhite commented on July 19, 2024

Closing.

from errors.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.