Comments (6)
@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.
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.
// 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.
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.
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.
Closing.
from errors.
Related Issues (20)
- Proposal: add errors.Is and errors.As
- RFC: Allow custom StackTraces
- func Is() does not works with errors.Wrap or errors.Wrapf HOT 3
- Cause() behavior has changed HOT 11
- respect -trimpath build flag HOT 3
- Unwrap doesn't return the base error HOT 7
- Questions about extending annotations HOT 5
- undefined errors.Wrap HOT 2
- How to change format return wrapped error message HOT 2
- Stacktrace don't print all stack HOT 6
- errors.Wrap() created bugs in our codebase. HOT 3
- StackTrace.Format with "%+v" includes a leading newline HOT 1
- A new error caused by another error HOT 7
- Demo
- Change Wrap() to return an error even if we provide nil HOT 3
- return *stack instead of stack HOT 2
- Wrap() duplicates call stack HOT 6
- Elegant way to check error is wrapped HOT 4
- `Errorf` should be able to wrap errors HOT 4
- Package errors looking for new maintainers HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from errors.