Documentation ¶
Overview ¶
Package eloc provides tools to add a stack trace to errors so that their origin can be easily located.
As described in the "Errors" section of Effective Go, it is good practice for library authors to add enough context to an error string to identify its origin. Since a library's implementation should be hidden behind its well-defined interface, library authors should not misuse eloc as an excuse for bad error messages to their users. References to the stack of a library contradict the above idea of encapsulation. Here eloc should be seen as a helpful addition during the development of the library.
This advice is also recommended to developers of executables! Here, however, some compromises may be tolerable.
Index ¶
- func At(err error) error
- func Errorf(format string, a ...any) error
- func FmtFrame(w io.Writer, err Error)
- func FmtShortStack(w io.Writer, err Error)
- func FmtStack(w io.Writer, err Error)
- func Frame(err error) runtime.Frame
- func New(text string) error
- func ParseEnv(s string) error
- func RecoverAs(err *error)
- func Ret[R any](v R, err error) (R, error)
- func Stack(err error, do func(*runtime.Frame) (cont bool))
- type Error
- type Formatter
- type FormatterFunc
- type ShortStack
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FmtShortStack ¶
func RecoverAs ¶
func RecoverAs(err *error)
Example (Error) ¶
err := testMustCall(errors.New("ERROR")) fmt.Println(err)
Output: ERROR @[eloc.testPanic enabled_test.go:63]
Example (ErrorStack) ¶
ErrorFmt = FormatterFunc(FmtShortStack) err := testMustCall(errors.New("ERROR")) fmt.Println(err)
Output: ERROR @[eloc.testPanic@enabled_test.go:63,68,94/run_example.go:63/example.go:44/testing.go:1927/_testmain.go:65/proc.go:267/asm_amd64.s:1650]
Example (String) ¶
err := testMustCall("STRING") fmt.Println(err)
Output: STRING @[eloc.testPanic enabled_test.go:63]
Types ¶
type Formatter ¶
var ( // Disabled allows to disable/enable all error location handling through // eloc. If this runtime switch is not enough one can also use the Go build // tag 'eloc_off' to remove eloc location handling during comiple time. In // that case setting Disabled has o effect. Disbaled atomic.Bool ErrorFmt Formatter = FormatterFunc(FmtShortStack) )
type FormatterFunc ¶
type ShortStack ¶
type ShortStack struct {
// contains filtered or unexported fields
}
func (*ShortStack) String ¶
func (s *ShortStack) String() string
Directories ¶
Path | Synopsis |
---|---|
Package must is an experiment to see if a concise way to work with panics will break Go's convention to explicitly check for errors as described in https://blog.golang.org/error-handling-and-go.
|
Package must is an experiment to see if a concise way to work with panics will break Go's convention to explicitly check for errors as described in https://blog.golang.org/error-handling-and-go. |