forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
panic_printer.go
66 lines (50 loc) · 1.56 KB
/
panic_printer.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
package panic_printer
import (
"fmt"
"github.com/cloudfoundry/cli/cf"
"github.com/cloudfoundry/cli/cf/errors"
"github.com/cloudfoundry/cli/cf/terminal"
)
var UI terminal.UI
func DisplayCrashDialog(err interface{}, commandArgs string, stackTrace string) {
if err != nil && err != terminal.QuietPanic {
switch err := err.(type) {
case errors.Exception:
if err.DisplayCrashDialog {
UI.Say(CrashDialog(err.Message, commandArgs, stackTrace))
} else {
fmt.Println(err.Message)
}
case error:
UI.Say(CrashDialog(err.Error(), commandArgs, stackTrace))
case string:
UI.Say(CrashDialog(err, commandArgs, stackTrace))
default:
UI.Say(CrashDialog("An unexpected type of error", commandArgs, stackTrace))
}
}
}
func CrashDialog(errorMessage string, commandArgs string, stackTrace string) string {
formattedString := `
Something unexpected happened. This is a bug in %s.
Please re-run the command that caused this exception with the environment
variable CF_TRACE set to true.
Also, please update to the latest cli and try the command again:
https://github.com/cloudfoundry/cli/releases
Please create an issue at: https://github.com/cloudfoundry/cli/issues
Include the below information when creating the issue:
Command
%s
CLI Version
%s
Error
%s
Stack Trace
%s
Your Platform Details
e.g. Mac OS X 10.11, Windows 8.1 64-bit, Ubuntu 14.04.3 64-bit
Shell
e.g. Terminal, iTerm, Powershell, Cygwin, gnome-terminal, terminator
`
return fmt.Sprintf(formattedString, cf.Name(), commandArgs, cf.Version, errorMessage, stackTrace)
}