github.com/asifdxtreme/cli@v6.1.3-0.20150123051144-9ead8700b4ae+incompatible/cf/panic_printer/panic_printer.go (about) 1 package panic_printer 2 3 import ( 4 "fmt" 5 6 "github.com/cloudfoundry/cli/cf" 7 "github.com/cloudfoundry/cli/cf/errors" 8 "github.com/cloudfoundry/cli/cf/terminal" 9 ) 10 11 var UI terminal.UI 12 13 func DisplayCrashDialog(err interface{}, commandArgs string, stackTrace string) { 14 if err != nil && err != terminal.QuietPanic { 15 switch err := err.(type) { 16 case errors.Exception: 17 if err.DisplayCrashDialog { 18 printCrashDialog(err.Message, commandArgs, stackTrace) 19 } else { 20 fmt.Println(err.Message) 21 } 22 case error: 23 printCrashDialog(err.Error(), commandArgs, stackTrace) 24 case string: 25 printCrashDialog(err, commandArgs, stackTrace) 26 default: 27 printCrashDialog("An unexpected type of error", commandArgs, stackTrace) 28 } 29 } 30 } 31 32 func CrashDialog(errorMessage string, commandArgs string, stackTrace string) string { 33 formattedString := ` 34 35 Aww shucks. 36 37 Something completely unexpected happened. This is a bug in %s. 38 Please file this bug : https://github.com/cloudfoundry/cli/issues 39 Tell us that you ran this command: 40 41 %s 42 43 using this version of the CLI: 44 45 %s 46 47 and that this error occurred: 48 49 %s 50 51 and this stack trace: 52 53 %s 54 ` 55 56 return fmt.Sprintf(formattedString, cf.Name(), commandArgs, cf.Version, errorMessage, stackTrace) 57 } 58 59 func printCrashDialog(errorMessage string, commandArgs string, stackTrace string) { 60 UI.Say(CrashDialog(errorMessage, commandArgs, stackTrace)) 61 }