A static analysis tool that ensures all goroutines have proper panic recovery via defer common.LogOnPanic() calls.
This linter was migrated from status-go to be a standalone tool for checking that all goroutines include the necessary defer statement to handle panics properly.
The linter analyzes Go code to find goroutines and ensures that:
- Anonymous goroutines have
defer common.LogOnPanic()as their first statement - Function call goroutines call functions that have
defer common.LogOnPanic()as their first statement - Method call goroutines call methods that have
defer common.LogOnPanic()as their first statement
go install github.com/status-im/goroutine-defer-guard/cmd/goroutine-defer-guard@latest# Run on current directory
goroutine-defer-guard ./...
# Skip certain directories
goroutine-defer-guard -skip=./vendor ./...go func() {
defer common.LogOnPanic()
// ... rest of function
}()go func() {
// Missing defer common.LogOnPanic()
// ... rest of function
}()func worker() {
defer common.LogOnPanic()
// ... rest of function
}
// Usage
go worker()The linter uses:
- AST analysis to find
gostatements (goroutines) - Go type information to resolve function/method definitions
- Static analysis to verify the first statement is
defer common.LogOnPanic()
- Go 1.21+
Mozilla Public License 2.0