ztrue/tracerr
ztrue/tracerr has 1,126 GitHub stars and 43 forks. GitHot measured 0 stars in 24 hours. Last checked 2026-11-09 09:34 UTC. Last push 2026-04-02.
Golang errors with stack trace and source fragments.
Measured star growth
- in 24h
- 0
- in 7 days
- Collecting history
- in 15 days
- Collecting history
- in 1 month
- Collecting history
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
README.md
OriginalGolang Errors with Stack Trace and Source Fragments
Tired of uninformative error output? Probably this will be more convenient:

Example
package main
import (
"io/ioutil"
"github.com/ztrue/tracerr"
)
func main() {
if err := read(); err != nil {
tracerr.PrintSourceColor(err)
}
}
func read() error {
return readNonExistent()
}
func readNonExistent() error {
_, err := ioutil.ReadFile("/tmp/non_existent_file")
// Add stack trace to existing error, no matter if it's nil.
return tracerr.Wrap(err)
}
Find more executable examples in examples dir.
How to Use
Import
import "github.com/ztrue/tracerr"
Create New Error
err := tracerr.New("some error")
Or:
err := tracerr.Errorf("some error %d", num)
Add Stack Trace to Existing Error
If
errisnilthen it still benilwith no stack trace added.
err = tracerr.Wrap(err)
Print Error and Stack Trace
Stack trace will be printed only if
erris of typetracerr.Error, otherwise just error text will be shown.
This will print error message and stack trace if any:
tracerr.Print(err)
This will add source code:
tracerr.PrintSource(err)
It's able to set up number of lines of code to display for each frame, which is 6 by default:
tracerr.PrintSource(err, 9)
Or to set up number of lines before and after traced line:
tracerr.PrintSource(err, 5, 2)
The same, but with color, which is much more useful:
tracerr.PrintSourceColor(err)
tracerr.PrintSourceColor(err, 9)
tracerr.PrintSourceColor(err, 5, 2)
Save Output to Variable
It's also able to save output to variable instead of printing it, which works the same way:
text := tracerr.Sprint(err)
text := tracerr.SprintSource(err)
text := tracerr.SprintSource(err, 9)
text := tracerr.SprintSource(err, 5, 2)
Get Stack Trace
Stack trace will be empty if
erris not an instance oftracerr.Error.
frames := tracerr.StackTrace(err)
Or if err is of type tracerr.Error:
frames := err.StackTrace()
Get Original Error
Unwrapped error will be
niliferrisniland will be the same error iferris not an instance oftracerr.Error.
err = tracerr.Unwrap(err)
Or if err is of type tracerr.Error:
err = err.Unwrap()
Performance
Benchmarks for creating a new error with a stack trace of different depth:
GOMAXPROCS=1 go test -bench=. -benchmem
goos: linux
goarch: amd64
pkg: github.com/ztrue/tracerr
cpu: Intel(R) Core(TM) i7-14700KF
BenchmarkNew/5 4500129 267.1 ns/op 256 B/op 4 allocs/op
BenchmarkNew/10 3325456 359.5 ns/op 256 B/op 4 allocs/op
BenchmarkNew/20 1000000 1001 ns/op 576 B/op 5 allocs/op
BenchmarkNew/40 538689 2171 ns/op 1216 B/op 6 allocs/op
PASS
ok github.com/ztrue/tracerr 5.246s
Explore related projects
affaan-m/ECC
The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.
300,167 starsNousResearch/hermes-agent
The agent that grows with you
262,037 starsmultica-ai/andrej-karpathy-skills
A single CLAUDE.md file to improve Claude Code behavior, derived from Andrej Karpathy's observations on LLM coding pitfalls.
231,308 starsfirecrawl/firecrawl
Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥
199,847 stars