-
Notifications
You must be signed in to change notification settings - Fork 0
/
bug.go
73 lines (62 loc) · 1.44 KB
/
bug.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
"runtime"
"time"
)
var report = struct {
CursorX int `json:"cursor_x,omitempty"`
CursorY int `json:"cursor_y,omitempty"`
Pane *Pane `json:"pane,omitempty"`
Lines []string `json:"lines,omitempty"`
}{}
func writeReport(reason interface{}) {
if reason == nil {
return
}
encodedReport, _ := json.MarshalIndent(report, " ", " ")
stacktrace := getStacktrace()
filename := filepath.Join(
os.TempDir(),
"tmux-autocomplete_panic_"+time.Now().Format(time.RFC3339Nano)+".log",
)
data := []byte(
fmt.Sprintf(
"bug report: tmux-autocomplete %s %s\n\n%s\n%s\n%s\n",
release,
version,
reason,
stacktrace,
encodedReport,
),
)
err := ioutil.WriteFile(filename, data, 0644)
if err != nil {
log.Printf("unable to write bug report into file: %q", filename)
log.Println(string(data))
os.Exit(137)
}
fmt.Fprintf(os.Stderr,
"The program exited unexpectedly, it means that you've encountered a bug,\n"+
"but we have collected the bug report.\n\n"+
"Make sure the file doesn't have any sensitive information: %s\n"+
"Please help us to solve the bug by sending this report to [email protected]\n",
filename,
)
os.Exit(137)
}
func getStacktrace() []byte {
buffer := make([]byte, 1024)
for {
stack := runtime.Stack(buffer, true)
if stack < len(buffer) {
return buffer[:stack]
}
buffer = make([]byte, 2*len(buffer))
}
}