Go

Fix Go production panics automatically

When a handler in your Go service panics, Bugstack works out the cause and sends the fix as a pull request: a nil pointer dereference, an index out of range, a send on a closed channel. The SDK works with net/http, Gin, Echo and Fiber.

What Go Errors Bugstack Fixes

  • nil pointer dereference — accessing fields or methods on nil pointers
  • index out of range — accessing slices or arrays beyond their bounds
  • send on closed channel — writing to a channel that has already been closed

Install the SDK

Install the SDK:

go get github.com/MasonBachmann7/bugstack-go

Then initialize it with your API key and the Bugstack endpoint, and wrap your handler:

// In main.go:
import bugstack "github.com/MasonBachmann7/bugstack-go"

endpoint := os.Getenv("BUGSTACK_ENDPOINT")
if endpoint == "" {
    endpoint = "https://dashboard.bugstack.ai/api/ingest/sdk"
}
bugstack.Init(bugstack.Config{
    APIKey:   os.Getenv("BUGSTACK_API_KEY"),
    Endpoint: endpoint,
})
defer bugstack.Flush()

// Report panics from your handlers:
import "github.com/MasonBachmann7/bugstack-go/middleware"

http.ListenAndServe(":8080", middleware.NetHTTP(mux))

Gin, Echo and Fiber, panic recovery and manual capture are in the installation guide. A concurrent map write or a deadlock is a Go fatal error, not a panic, so no SDK can report it.

Example Fix

Bugstack detects a nil pointer dereference panic and writes a small fix:

Before (broken)

func GetUserEmail(id int) string {
    user := findUserByID(id)
    return user.Email
}

// Runtime panic when user is nil:
// panic: runtime error: invalid
//   memory address or nil pointer
//   dereference

After (fixed by Bugstack)

func GetUserEmail(id int) (string, error) {
    user := findUserByID(id)
    if user == nil {
        return "", fmt.Errorf(
            "user %d not found", id,
        )
    }
    return user.Email, nil
}

Proven before you see it

Bugstack does not send this fix on trust. In an isolated copy of your repository, with the network cut, it writes a test that reproduces the crash and runs it with go test on your current code: it fails with the same nil pointer panic. With the fix the test passes, and the rest of your suite still passes. Only then does the pull request open, with the test and that proof in it.

The reproduction test, shipped in the pull request

func TestGetUserEmailUnknownUser(t *testing.T) {
    defer func() {
        if r := recover(); r != nil {
            // Before the fix: invalid memory address
            //   or nil pointer dereference
            t.Fatalf("panicked: %v", r)
        }
    }()
    GetUserEmail(-1)
}

See how the verification sandbox works.

What else Bugstack does for this repository

The SDK is one part. Once your repository is connected, Bugstack also scans your Go modules for known vulnerabilities and outdated versions, scans for secrets, and acts on failed deploys if you host on Render. It scans and reports, and it can open pull requests for what it finds. Those pull requests are switched on per account. Every change arrives as a pull request, and you set how much happens without you.

Full installation guide with config reference →

See it work on your own code.

$100 a month

Includes $100 of usage credit every month. Start with a 14-day trial: $50 of credit and a first security audit on us. A card is required.