This release supports compile-time rewriting of source files via toolexec.
Build your package or binary with go build -toolexec errtrace and all packages
that import errtrace will be automatically instrumented with errtrace.
Added
-
Add
UnwrapFramefunction to extract a single frame from an error.
You can use this to implement your own trace formatting logic. -
Support extracting trace frames from custom errors.
Any error value that implementsTracePC() uintptrwill now
contribute to the trace. -
Add
GetCallerfunction for error helpers to annotate wrapped errors with
their caller information instead of the helper. Example://go:noinline func Wrapf(err error, msg string, args ...any) { caller := errtrace.GetCaller() err := ... return caller.Wrap(err) }
-
Implement
slog.LogValuerso errors logged with log/slog log the full trace. -
cmd/errtrace:
Add-no-wrapnoption to disable wrapping with genericWrapNfunctions.
This is only useful for toolexec mode due to tooling limitations. -
cmd/errtrace:
Experimental support for instrumenting code with errtrace automatically
as part of the Go build process.
Try this out withgo build -toolexec=errtrace pkg/to/build.
Automatic instrumentation only rewrites packages that import errtrace.
The flag-required-packagescan be used to specify which packages
are expected to import errtrace if they require rewrites.
Example:go build -toolexec="errtrace -required-packages pkg/..." pkg/to/build
Changed
- Update
godirective in go.mod to 1.21, and drop compatibility with Go 1.20 and earlier. - Errors wrapped with errtrace are now compatible with log/slog-based loggers,
and will report the full error trace when logged.
Fixed
- cmd/errtrace: Don't exit with a non-zero status when
-his used. - cmd/errtrace: Don't panic on imbalanced assignments inside defer blocks.