disgo
disgo copied to clipboard
Prompt to create github issue on unhandled error
The idea is if an error has not been handled in code, prompt user to submit the error code and callstack to github. This could be a setting only for alpha/beta releases. Example:
f, err := os.Open("filename.ext")
if err != nil && reportError() {
openbrowser("https://github.com/dispatchlabs/disgo/issues/new?title=Missing fil%20to%20invalid%20chain%3A%20%5Bunknown%2C%200%5D&body=%60%60%60%20%0AError%3A%20Launcher%20co")
}
func openbrowser(url string) {
var err error
switch runtime.GOOS {
case "linux":
err = exec.Command("xdg-open", url).Start()
case "windows":
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
case "darwin":
err = exec.Command("open", url).Start()
default:
err = fmt.Errorf("unsupported platform")
}
if err != nil {
log.Fatal(err)
}
}
func reportError() bool {
var response string
_, err := fmt.Scanln(&response)
if err != nil {
log.Fatal(err)
}
okayResponses := []string{"y", "Y", "yes", "Yes", "YES"}
nokayResponses := []string{"n", "N", "no", "No", "NO"}
if containsString(okayResponses, response) {
return true
} else if containsString(nokayResponses, response) {
return false
} else {
fmt.Println("Report error? Type yes or no and then press enter:")
return reportError()
}
}