go.panic_in_library
Stability
High
Detects panic() calls in library code that should return errors instead.
Why It Matters
Section titled “Why It Matters”Panics in libraries:
- Crash calling applications — Library panic terminates the app
- Remove caller control — Callers can’t handle errors gracefully
- Violate Go conventions — Libraries should return errors
- Cause production outages — One bad input crashes everything
Example
Section titled “Example”// ❌ Before (panic in library)func Parse(data []byte) Config { if len(data) == 0 { panic("empty data") // Crashes caller! } // ...}// ✅ After (returns error)func Parse(data []byte) (Config, error) { if len(data) == 0 { return Config{}, errors.New("empty data") } // ...}What Unfault Detects
Section titled “What Unfault Detects”panic()in exported functionspanic()in package withoutmainpanic()for recoverable errors
Auto-Fix
Section titled “Auto-Fix”Unfault converts panic to error return:
func Process(input string) (Result, error) { if input == "" { return Result{}, errors.New("empty input") } // ...}