A Go library that enhances errors with stack traces and source code fragments for better debugging.
Tracerr is a Go library that enhances standard errors by automatically attaching stack traces and displaying relevant source code fragments. It solves the problem of uninformative error messages in Go by providing immediate context about where an error originated, making debugging faster and more intuitive.
Go developers who need better error diagnostics during development and debugging, particularly those working on complex applications where tracking error origins is challenging.
Developers choose Tracerr because it offers a simple, lightweight way to get detailed error context without manual logging, with features like colorized source output and flexible formatting that integrate seamlessly into existing Go error handling.
Golang errors with stack trace and source fragments.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Automatically attaches call stack information to errors on creation or wrapping, providing immediate debugging context without manual logging, as shown in the Wrap function.
Displays configurable lines of source code around error locations, with flexible functions like PrintSource allowing custom line ranges for quick context.
Offers syntax-highlighted source code in terminals via PrintSourceColor, making error outputs more readable during development, as demonstrated in the example.
Benchmarks show efficient memory allocation and speed even with deep stack traces, with low allocs/op as per the provided performance data.
Provides Unwrap methods to retrieve original errors, maintaining compatibility with Go's error handling patterns while adding trace context.
Stack traces and source fragments only apply if errors are explicitly wrapped with tracerr; standard errors lose these features unless converted, reducing seamless integration.
Although optimized, attaching stack traces incurs additional memory and CPU costs compared to plain errors, as benchmarks show allocation increases with trace depth.
Colorized output is designed for terminals and may not render correctly in logs or non-terminal environments, limiting its utility in production logging setups.