MCPcopy Create free account
hub / github.com/anchordotdev/cli / CapturePanic

Function CapturePanic

stacktrace/stacktrace.go:28–42  ·  view source on GitHub ↗
(fn func() error)

Source from the content-addressed store, hash-verified

26}
27
28func CapturePanic(fn func() error) (err error) {
29 defer func() {
30 if msg := recover(); msg != nil {
31 stack := debug.Stack()
32
33 err = Error{
34 error: fmt.Errorf("%s", msg),
35 Stack: defaultCleaner.clean(string(stack)),
36 }
37 }
38 }()
39
40 err = fn()
41 return
42}
43
44type Error struct {
45 error

Callers 3

NewCmdFunction · 0.92
TestErrorFunction · 0.92
TestPanicFunction · 0.92

Calls 1

cleanMethod · 0.80

Tested by 2

TestErrorFunction · 0.74
TestPanicFunction · 0.74