Skip to content

Automatically report your programs panic to their github repository

License

Notifications You must be signed in to change notification settings

mh-cbon/report-panic

Repository files navigation

report-panic

Go Report Card

GoDoc

Package reportpanic Automatically report your programs panic.

TOC

API example

Report to a github repository

> demo/gh_demo.go
// +build ignore

package main

import (
	"github.com/mh-cbon/report-panic"
)

// wrap your main code with reportpanic.HandleMain,
// provide it a reporter such as Gh

func main() {
	reportpanic.HandleMain(reportpanic.Gh("mh-cbon/demotest"), func() {
		panic("oh no!")
	})
}

Report to a google analytics account

> demo/ga_demo.go
// +build ignore

package main

import (
	"github.com/mh-cbon/report-panic"
)

// wrap your main code with reportpanic.HandleMain,
// provide it a reporter such as Gh

func main() {
	// Don t forget to change the GA ID.
	reportpanic.HandleMain(reportpanic.Ga("UA-93911415-1", "my-program", "0.0.1"), func() {
		panic("oh no!")
	})
}

Install

Glide

mkdir -p $GOPATH/src/github.com/mh-cbon/report-panic
cd $GOPATH/src/github.com/mh-cbon/report-panic
git clone https://github.com/mh-cbon/report-panic.git .
glide install
go install

Ga Configuration

You can only set

  • GA ID
  • Your program name
  • Your program version

The GA reporter will emit pageview on program start, panic as http://localhost/<program>/<version>/<action>

Gh Configuration

Change the github token reporter

To set a different token to report panics, add this flag to your build compilation --ldflags "-X reportpanic.GhReporterToken=xxxxx"

go build --ldflags "-X reportpanic.GhReporterToken=xxxxx"

Change the github template generating the body report

  1. Access to the templater instance of the reporter
package main

import (
  "github.com/mh-cbon/report-panic"
)

func main () {
  reporter := reportpanic.Gh("your_user/your_repo")
  reporter.Templater.Template = "template { {content} } here"
  reportpanic.HandleMain(reporter, func () {
    panic("oh no!")
  })
}
  1. Or, use ldflags at build time

At build time, use ldflags to configure the template

go build --ldflags "-X reportpanic.GhTemplate=your_tpl"

Register your_tpl to panicreport

package main

import (
  "github.com/mh-cbon/report-panic"
)

// register your template in the init, or main func
func init(){
  panicreport.PanicReportTemplates["your_tpl"] = "template { {content} } here"
}

func main() {
  reportpanic.HandleMain(reportpanic.Gh("your_user/your_repo"), func () {
    panic("oh no!")
  })
}

Recipes

Release the project

gump patch -d # check
gump patch # bump

Credits

Mitchell Hashimoto for the base code provided in panicwrap

About

Automatically report your programs panic to their github repository

Topics

Resources

License

Stars

Watchers

Forks

Packages