+0
Daily
997
stars
46
forks
7
watchers
126
prs
31
issues
44
releases
README
Oops - Structured Error Handling for Go
Transform your Go error handling from "oops!" to "aha!" moments
!Go Version
!Build Status
Oops is a comprehensive Go error handling library that provides structured error management with rich contextual information. It's designed as a drop-in replacement for Go's built-in error, adding powerful features like stack traces, source code fragments, structured attributes, and developer-friendly debugging hints.
🎯 Key Features:
- 🔧 Drop-in Replacement: Seamlessly replaces standard Go error handling
- 📊 Rich Context: Add structured attributes, user info
- 🐛 Debug-Friendly: Out-of-the-box stacktraces and source code fragments
- 🔗 Error Chaining: Wrap and compose errors with additional context
- 🛡️ Panic Recovery: Built-in panic handling with error conversion
- ✅ Assertions: One-line assertion helpers for validation
- ⚡ Performance: Zero dependencies, lightweight and fast
- 📝 Logger Integration: Works with all major Go logging libraries
- ✂️ Separation of Concerns: Error handling and logging are separate jobs
- 🍳 Easy Integration: No large refactoring required
[!WARNING]
Important: This is NOT a logging library. oops should complements your existing logging toolchain (zap, zerolog, logrus, slog, go-sentry...).
🥷 Start hacking oops with this playground.
Sponsored by:
Cut Kubernetes & AI costs, boost application stability
100% OpenTelemetry-native observability platformSimple to use, built on open standards, and designed for full cost control
Table of content
- 🚀 Install
- 💡 Quick start
- 🧠 Spec
- Error builder
- Context
- Other helpers
- Stack trace
- Source fragments
- Panic handling
- Assertions
- Output
- Go context
- 📫 Loggers
- 🥷 Tips and best practices
Context rich error handling
In a few minutes, your logs will look like this:
🚀 Install
sh
go get github.com/samber/oops
AI Agent Skill:
npx skills add https://github.com/samber/cc-skills-golang --skill golang-samber-oops
This library is v1 and follows SemVer strictly.
No breaking changes will be made to APIs before v2.0.0.
This library has no dependencies outside the Go standard library.
💡 Quick start
This library provides a simple error builder for composing structured errors, with contextual attributes and stack trace.
Since oops.OopsError implements the error interface, you will be able to compose and wrap native errors with oops.OopsError.
go
import "github.com/samber/oops"
func main() {
// Simple error with context
err := oops.
In("user-service").
Tags("database", "postgres").
Code("network_failure").
User("user-123", "email", "[email protected]").
With("path", "/hello/world").
Errorf("failed to fetch user: %s", "connection timeout")
// Error wrapping
if err != nil {
return oops.
Trace("req-123").
With("prodTop issues
#42[Proposal] Add the log level to the error builder5 comments · 2024-12-31#34Can you add LastPublic(), LastCode() API?4 comments · 2024-11-22#9Structured stacktrace?4 comments · 2023-08-25#3[Proposal] 🎨 Beautiful human readable logs4 comments · 2023-05-17#7Embed sources at compile time3 comments · 2023-05-18#1Zap example3 comments · 2023-05-16#81Feature Request: Allow adding context to an existing OopsError without regenerating stack trace2 comments · 2025-10-09#53Join: travel through nested contexts recursively2 comments · 2025-03-04
Latest release
v1.23.2 v1.23.2 2026-09-14What's Changed Look up Stringer context values using the original key by @vitalivo in https://github.com/samber/oops/pull/152 Dependencies chore(deps): bump github/codeql-action from 4.37.3 to 4.37.9 by @dependabot[bot] in https://github.com/samber/oops/pull/150 chore(deps): bump github.com/stretchr/testify from 1.11.1 to 1.12.1 by @dependabot[bot] in https://github.com/samber/oops/pull/148 chore(deps): bump github.com/sirupsen/logrus from 1.9.4 to 1.10.2 by @dependabot[bot] in https://github.com/samber/oops/pull/147 Revert "chore(deps): bump github.com/sirupsen/logrus from 1.9.4