Skip to content

Commit 9b5e417

Browse files
committed
explain error return traces and add link to Zig
1 parent fd2d889 commit 9b5e417

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

tracer.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,23 @@ func LogTracer() io.Writer {
2727
}
2828

2929
// SetErrorTracer sets a [io.Writer] for automatic error stack tracing. The err2
30-
// default is nil. Note that the current function is capable to print error
31-
// stack trace when the function has at least one deferred error handler, e.g:
30+
// default is nil. Note that any function that has deferred [Handle] or [Catch]
31+
// is capable to print error stack trace:
3232
//
3333
// func CopyFile(src, dst string) (err error) {
34-
// defer err2.Handle(&err) // <- error trace print decision is done here
34+
// defer err2.Handle(&err) // <- makes error trace printing decision
35+
//
36+
// Error trace is almost the same format as Go's standard call stack but it may
37+
// have multiple sections because every [Handle] and [Catch] prints it. If an
38+
// error happens in a deep call stack, the error trace includes various parts.
39+
// The principle is similar to [Zig Error Return Traces], where you see how
40+
// error bubbles up. However, our error trace is a combination of error return
41+
// traces and stack traces because we get all the needed information at once.
3542
//
3643
// Remember that you can reset these with [flag] package support. See
3744
// documentation of err2 package's flag section.
45+
//
46+
// [Zig Error Return Traces]: https://ziglang.org/documentation/master/#Error-Return-Traces
3847
func SetErrorTracer(w io.Writer) {
3948
tracer.Error.SetTracer(w)
4049
}

0 commit comments

Comments
 (0)