You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I made a spiritual successor of github.com/pkg/errors some time ago and in it I want to know if an error already contains a stack trace. The goal is that if a large codebase uses different packages for errors, they should work together and not hide existing recorded information, like a stack trace.
From what I am seeing in this package is that it has the same issue as github.com/pkg/errors: the return value of StackTrace() is a custom type defined in this package. So it is not possible to detect the error having this method without importing this package.
I would suggest that instead, the following interface is implemented:
type stackTracer interface {
StackTrace() []uintptr
}
Then, it is easy to obtain a stack trace, use it, format it, and one does not have to depend on a library which created the error.
To prevent a breaking change, I have seen also the following interface being used in this package:
type goErrorsStackTracer interface {
Callers() []uintptr
}
BTW, you are also using runtime.FuncForPC which is deprecated. And calling it runtime.FuncForPC at the time of making a stack trace is quite a performance hit. It is much better to just record a stack trace (into []uintptr) when making an error and then resolve addresses with runtime.FuncForPC when the stack is formatted (if ever).
The text was updated successfully, but these errors were encountered:
I made a spiritual successor of
github.com/pkg/errors
some time ago and in it I want to know if an error already contains a stack trace. The goal is that if a large codebase uses different packages for errors, they should work together and not hide existing recorded information, like a stack trace.From what I am seeing in this package is that it has the same issue as
github.com/pkg/errors
: the return value ofStackTrace()
is a custom type defined in this package. So it is not possible to detect the error having this method without importing this package.I would suggest that instead, the following interface is implemented:
Then, it is easy to obtain a stack trace, use it, format it, and one does not have to depend on a library which created the error.
To prevent a breaking change, I have seen also the following interface being used in this package:
BTW, you are also using
runtime.FuncForPC
which is deprecated. And calling itruntime.FuncForPC
at the time of making a stack trace is quite a performance hit. It is much better to just record a stack trace (into[]uintptr
) when making an error and then resolve addresses withruntime.FuncForPC
when the stack is formatted (if ever).The text was updated successfully, but these errors were encountered: