Documentation
¶
Overview ¶
Package crashreport turns an otherwise-silent panic into something a non-technical tester can act on: it writes a crash report file next to the binary, prints a pre-filled GitHub "new issue" link, and (for GUI builds with no visible console) opens that link in the browser. See issue #165.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Guard ¶ added in v1.15.0
func Guard()
Guard is deferred at the top of every long-lived goroutine:
go func() {
defer crashreport.Guard()
...
}()
A panic in a goroutine cannot be caught by a deferred Recover in main — Go unwinds only the panicking goroutine's stack — so an unguarded goroutine panic kills the whole process with a bare stack trace the GUI user never sees (issue #234). Guard writes a crash report, surfaces the prefilled issue link (opening the browser per SetOpenBrowser), and exits the process.
func GuardNonFatal ¶ added in v1.15.0
func GuardNonFatal(cleanup func())
GuardNonFatal is deferred at the top of a goroutine that must NOT take down the process on panic — e.g. a single ingest run, whose death should leave the dashboard serving. On a panic it reports the crash (via Report) and runs the optional cleanup so the caller can mark its work failed, then lets the goroutine unwind normally. Unlike Guard it never exits. Deferred as:
defer crashreport.GuardNonFatal(func() { d.finishIngest(err) })
func Handle ¶
Handle processes an already-recovered panic. It is exported (separately from Recover) so callers that capture the stack themselves, and tests, can drive it directly. It never re-panics.
func Recover ¶
func Recover(openBrowser bool)
Recover is meant to be deferred at the top of main() or a long-lived goroutine:
defer crashreport.Recover(false)
On a non-nil panic it writes a crash report, surfaces a pre-filled issue link (opening the browser when openBrowser is true, for GUI builds), and exits the process. On a clean return it does nothing.
func ReportPanic ¶ added in v1.15.0
ReportPanic writes a crash report for an already-recovered panic and surfaces the prefilled issue link (opening the browser per SetOpenBrowser) WITHOUT exiting. Use it for inline recovery where the surrounding loop should skip the failed item and keep going (the caller captures the stack in its own recover).
func SetOpenBrowser ¶ added in v1.15.0
func SetOpenBrowser(open bool)
SetOpenBrowser sets the process-wide browser preference for crash reports. An entrypoint should call it once at startup, before spawning goroutines.
Types ¶
type Report ¶
type Report struct {
When time.Time
Version string
Commit string
GOOS string
GOARCH string
Cause string // the recovered panic value, formatted
Stack string // full goroutine stack from debug.Stack()
}
Report captures everything known about a crash at the moment it happened.