samber /oops

🔥 Error handling library with context, assertion, stack trace and source fragments

★ 997⑂ 46👁 7⑃ 126● 31▤ 44
GoMITCreated 2023-05-16pkg.go.dev/github.com/samber/oops
Download: v1.23.2v1.23.2 ↓1.23.22026-09-14
+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("prod

Top issues

Latest release

v1.23.2 v1.23.2 2026-09-14
What'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

Snapshot: 2026-11-27T22:26:53Z · Data license Apache-2.0 · JSON