forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
panic_printer.go
61 lines (45 loc) · 1.35 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
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 {
printCrashDialog(err.Message, commandArgs, stackTrace)
} else {
fmt.Println(err.Message)
}
case error:
printCrashDialog(err.Error(), commandArgs, stackTrace)
case string:
printCrashDialog(err, commandArgs, stackTrace)
default:
printCrashDialog("An unexpected type of error", commandArgs, stackTrace)
}
}
}
func CrashDialog(errorMessage string, commandArgs string, stackTrace string) string {
formattedString := `
Aww shucks.
Something completely unexpected happened. This is a bug in %s.
Please file this bug : https://github.com/cloudfoundry/cli/issues
Tell us that you ran this command:
%s
using this version of the CLI:
%s
and that this error occurred:
%s
and this stack trace:
%s
`
return fmt.Sprintf(formattedString, cf.Name(), commandArgs, cf.Version, errorMessage, stackTrace)
}
func printCrashDialog(errorMessage string, commandArgs string, stackTrace string) {
UI.Say(CrashDialog(errorMessage, commandArgs, stackTrace))
}