MCPcopy Index your code
hub / github.com/cloudfoundry/cli / HandlePanic

Function HandlePanic

util/panichandler/handler.go:17–77  ·  view source on GitHub ↗

HandlePanic will recover from any panics and display a friendly error message with additional information used for debugging the panic.

()

Source from the content-addressed store, hash-verified

15// HandlePanic will recover from any panics and display a friendly error
16// message with additional information used for debugging the panic.
17func HandlePanic() {
18 stackTraceBytes := make([]byte, maxStackSizeLimit)
19 runtime.Stack(stackTraceBytes, true)
20 stackTrace := "\t" + strings.Replace(string(stackTraceBytes), "\n", "\n\t", -1)
21 if err := recover(); err != nil {
22 formattedString := `
23 Something unexpected happened. This is a bug in {{.Binary}}.
24
25 Please re-run the command that caused this exception with the environment
26 variable CF_TRACE set to true.
27
28 Also, please update to the latest cli and try the command again:
29 https://code.cloudfoundry.org/cli/v8/releases
30
31 Please create an issue at: https://code.cloudfoundry.org/cli/v8/issues
32
33 Include the below information when creating the issue:
34
35 Command
36 {{.Command}}
37
38 CLI Version
39 {{.Version}}
40
41 Error
42 {{.Error}}
43
44 Stack Trace
45 {{.StackTrace}}
46
47 Your Platform Details
48 e.g. Mac OS X 10.11, Windows 8.1 64-bit, Ubuntu 14.04.3 64-bit
49
50 Shell
51 e.g. Terminal, iTerm, Powershell, Cygwin, gnome-terminal, terminator
52 `
53 formattedTemplate := template.Must(template.New("Panic Template").Parse(formattedString))
54 templateErr := formattedTemplate.Execute(os.Stderr, map[string]interface{}{
55 "Binary": os.Args[0],
56 "Command": strings.Join(os.Args, " "),
57 "Version": version.VersionString(),
58 "StackTrace": stackTrace,
59 "Error": err,
60 })
61 if templateErr != nil {
62 fmt.Fprintf(os.Stderr,
63 "Unable to format panic response: %s\n",
64 templateErr.Error(),
65 )
66
67 fmt.Fprintf(os.Stderr,
68 "Version:%s\nCommand:%s\nOriginal Stack Trace:%s\nOriginal Error:%s\n",
69 version.VersionString(),
70 strings.Join(os.Args, " "),
71 stackTrace,
72 err,
73 )
74 }

Callers 1

mainFunction · 0.92

Calls 6

VersionStringFunction · 0.92
StackMethod · 0.65
ParseMethod · 0.65
ExecuteMethod · 0.65
ErrorMethod · 0.65
ExitMethod · 0.65

Tested by

no test coverage detected