github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/internal/runbits/panics/panics.go (about) 1 package panics 2 3 import ( 4 "fmt" 5 "os" 6 7 "github.com/ActiveState/cli/internal/constants" 8 "github.com/ActiveState/cli/internal/logging" 9 "github.com/ActiveState/cli/internal/multilog" 10 ) 11 12 // HandlePanics produces actionable output for panic events (that shouldn't happen) and returns whether a panic event has been handled 13 func HandlePanics(recovered interface{}, stack []byte) bool { 14 if recovered != nil { 15 multilog.Error("Panic: %v", recovered) 16 logging.Debug("Stack: %s", string(stack)) 17 18 fmt.Fprintf(os.Stderr, `An unexpected error occurred. 19 Error: %v 20 Stack trace: %s 21 Check the error log for more information: %s 22 Please consider reporting your issue on the forums: %s`, recovered, string(stack), logging.FilePath(), constants.ForumsURL) 23 return true 24 } 25 return false 26 } 27 28 // LogPanics produces actionable output for panic events (that shouldn't happen) and returns whether a panic event has been handled 29 func LogPanics(recovered interface{}, stack []byte) bool { 30 if recovered != nil { 31 multilog.Error("Panic: %v", recovered) 32 logging.Debug("Stack: %s", string(stack)) 33 return true 34 } 35 return false 36 }