1
1
mirror of https://github.com/walles/moar.git synced 2024-11-22 11:45:50 +03:00

Print bug reporting instructions on panics

This commit is contained in:
Johan Walles 2019-07-08 06:42:48 +02:00
parent 17787b1212
commit 31ae7927c7
2 changed files with 29 additions and 3 deletions

30
moar.go
View File

@ -6,6 +6,7 @@ import (
"io"
"log"
"os"
"runtime"
"strings"
"github.com/gdamore/tcell"
@ -17,7 +18,29 @@ import (
var versionString = "Should be set when building, please use build.sh to build"
func main() {
// FIXME: On any panic or warnings, also print system info and how to report bugs
defer func() {
err := recover()
if err == nil {
return
}
// On any panic or warnings, also print system info and how to report bugs
fmt.Fprintln(os.Stderr, "Please post the following crash report at <https://github.com/walles/moar/issues>,")
fmt.Fprintln(os.Stderr, "or e-mail it to johan.walles@gmail.com.")
fmt.Fprintln(os.Stderr)
fmt.Fprintln(os.Stderr, "Version:", versionString)
fmt.Fprintln(os.Stderr, "LANG :", os.Getenv("LANG"))
fmt.Fprintln(os.Stderr, "TERM :", os.Getenv("TERM"))
fmt.Fprintln(os.Stderr)
fmt.Fprintln(os.Stderr, "GOOS :", runtime.GOOS)
fmt.Fprintln(os.Stderr, "GOARCH :", runtime.GOARCH)
fmt.Fprintln(os.Stderr, "Compiler:", runtime.Compiler)
fmt.Fprintln(os.Stderr, "NumCPU :", runtime.NumCPU())
fmt.Fprintln(os.Stderr)
panic(err)
}()
printVersion := flag.Bool("version", false, "Prints the moar version number")
@ -84,8 +107,7 @@ func main() {
func _StartPaging(reader *m.Reader) {
screen, e := tcell.NewScreen()
if e != nil {
fmt.Fprintf(os.Stderr, "%v\n", e)
os.Exit(1)
panic(e)
}
var loglines strings.Builder
@ -100,6 +122,8 @@ func _StartPaging(reader *m.Reader) {
}
if len(loglines.String()) > 0 {
// FIXME: Don't print duplicate log messages more than once,
// maybe invent our own logger for this?
fmt.Fprintf(os.Stderr, "%s", loglines.String())
os.Exit(1)
}

View File

@ -39,5 +39,7 @@ echo Test --version...
./moar --version > /dev/null # Should exit with code 0
diff -u <(./moar --version) <(git describe --tags --dirty)
# FIXME: Test some unknown command line option
echo
echo "All tests passed!"