mitchellh / panicwrap

panicwrap is a Go library for catching and handling panics in Go applications.
https://gist.github.com/mitchellh/90029601268e59a29e64e55bab1c5bdc
MIT License
443 stars 69 forks source link

How to catch panic in framework echo #21

Open AlexMain opened 6 years ago

AlexMain commented 6 years ago

Hello! I have a question. I'm using framework echo and want to catch panic of framework echo. panic in this framework looks like this

{"time":"2018-03-05T15:18:54.587819574+03:00","level":"-","prefix":"echo","file":"asm_amd64.s","line":"574","message":"[PANIC RECOVER] a problem goroutine 32 [running]:\ngithub.com/labstack/echo/middleware.RecoverWithConfig.func1.1.1(0x995168, 0x4000, 0xc420050000, 0x9e0e80, 0xc42022b960)\n\t/home/inverno/go_projects/src/github.com/labstack/echo/middleware/recover.go:71 +0xf7\npanic(0x8a83a0, 0x9d2890)\n\t/snap/go/1473/src/runtime/panic.go:505 +0x229\ngo-template-2/bar.Foo(0x9e0e80, 0xc42022b960, 0x0, 0x0)\n\t/home/inverno/go_projects/src/go-template-2/bar/bar.go:112 +0x391\ngithub.com/labstack/echo.(Echo).Add.func1(0x9e0e80, 0xc42022b960, 0x8, 0x8f4d60)\n\t/home/inverno/go_projects/src/github.com/labstack/echo/echo.go:477 +0x87\nmain.echoInit.func1.1(0x9e0e80, 0xc42022b960, 0x995168, 0x4000)\n\t/home/inverno/go_projects/src/go-template-2/main_init.go:47 +0x11e\ngithub.com/labstack/echo/middleware.RecoverWithConfig.func1.1(0x9e0e80, 0xc42022b960, 0x0, 0x0)\n\t/home/inverno/go_projects/src/github.com/labstack/echo/middleware/recover.go:78 +0xd7\ngithub.com/labstack/echo.(Echo).ServeHTTP.func1(0x9e0e80, 0xc42022b960, 0xc4203a4058, 0x9664a0)\n\t/home/inverno/go_projects/src/github.com/labstack/echo/echo.go:574 +0x108\ngithub.com/labstack/echo.(Echo).ServeHTTP(0xc4203a4000, 0x9d8e60, 0xc4203f2000, 0xc4203f0000)\n\t/home/inverno/go_projects/src/github.com/labstack/echo/echo.go:583 +0x215\nnet/http.serverHandler.ServeHTTP(0xc420350270, 0x9d8e60, 0xc4203f2000, 0xc4203f0000)\n\t/snap/go/1473/src/net/http/server.go:2694 +0xbc\nnet/http.(conn).serve(0xc4203ea000, 0x9d94e0, 0xc420298340)\n\t/snap/go/1473/src/net/http/server.go:1830 +0x651\ncreated by net/http.(Server).Serve\n\t/snap/go/1473/src/net/http/server.go:2795 +0x27b\n\ngoroutine 1 [IO wait]:\ninternal/poll.runtime_pollWait(0x7f912a402c90, 0x72, 0x0)\n\t/snap/go/1473/src/runtime/netpoll.go:173 +0x57\ninternal/poll.(pollDesc).wait(0xc420131a98, 0x72, 0xc420074000, 0x0, 0x0)\n\t/snap/go/1473/src/internal/poll/fd_poll_runtime.go:85 +0x9b\ninternal/poll.(pollDesc).waitRead(0xc420131a98, 0xffffffffffffff00, 0x0, 0x0)\n\t/snap/go/1473/src/internal/poll/fd_poll_runtime.go:90 +0x3d\ninternal/poll.(FD).Accept(0xc420131a80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)\n\t/snap/go/1473/src/internal/poll/fd_unix.go:372 +0x1a8\nnet.(netFD).accept(0xc420131a80, 0x411d01, 0xc4201894a0, 0x42aa14)\n\t/snap/go/1473/src/net/fd_unix.go:238 +0x42\nnet.(TCPListener).accept(0xc42000e308, 0x402e3c, 0xc4203ea080, 0xc4201894b0)\n\t/snap/go/1473/src/net/tcpsock_posix.go:136 +0x2e\nnet.(TCPListener).AcceptTCP(0xc42000e308, 0x401d27, 0xc4203ea080, 0x8c4900)\n\t/snap/go/1473/src/net/tcpsock.go:246 +0x49\ngithub.com/labstack/echo.tcpKeepAliveListener.Accept(0xc42000e308, 0xc420189528, 0xc420189530, 0x18, 0x6c8afb)\n\t/home/inverno/go_projects/src/github.com/labstack/echo/echo.go:717 +0x2f\nnet/http.(Server).Serve(0xc420350270, 0x9d8a20, 0xc42000e310, 0x0, 0x0)\n\t/snap/go/1473/src/net/http/server.go:2770 +0x1a5\ngithub.com/labstack/echo.(Echo).StartServer(0xc4203a4000, 0xc420350270, 0x1, 0xc42029ca40)\n\t/home/inverno/go_projects/src/github.com/labstack/echo/echo.go:650 +0x37d\ngithub.com/labstack/echo.(Echo).Start(0xc4203a4000, 0xc42029a0e0, 0x5, 0x0, 0x0)\n\t/home/inverno/go_projects/src/github.com/labstack/echo/echo.go:591 +0x53\nmain.main()\n\t/home/inverno/go_projects/src/go-template-2/main.go:497 +0x243a\n\ngoroutine 5 [syscall]:\nos/signal.signal_recv(0x0)\n\t/snap/go/1473/src/runtime/sigqueue.go:139 +0xa6\nos/signal.loop()\n\t/snap/go/1473/src/os/signal/signal_unix.go:22 +0x22\ncreated by os/signal.init.0\n\t/snap/go/1473/src/os/signal/signal_unix.go:28 +0x41\n\ngoroutine 45 [select]:\ndatabase/sql.(DB).connectionOpener(0xc4202be000, 0x9d94e0, 0xc420268100)\n\t/snap/go/1473/src/database/sql/sql.go:935 +0x119\ncreated by database/sql.OpenDB\n\t/snap/go/1473/src/database/sql/sql.go:634 +0x178\n\ngoroutine 18 [select]:\ngo-template-2/logger.ErrFileInit.func1()\n\t/home/inverno/go_projects/src/go-template-2/logger/logger.go:281 +0xef\ncreated by go-template-2/logger.ErrFileInit\n\t/home/inverno/go_projects/src/go-template-2/logger/logger.go:279 +0x35\n\ngoroutine 46 [select]:\ndatabase/sql.(DB).connectionResetter(0xc4202be000, 0x9d94e0, 0xc420268100)\n\t/snap/go/1473/src/database/sql/sql.go:948 +0x12a\ncreated by database/sql.OpenDB\n\t/snap/go/1473/src/database/sql/sql.go:635 +0x1ae\n\ngoroutine 33 [runnable]:\ndatabase/sql.(Tx).awaitDone(0xc4203c0100)\n\t/snap/go/1473/src/database/sql/sql.go:1839 +0x4b\ncreated by database/sql.(DB).beginDC\n\t/snap/go/1473/src/database/sql/sql.go:1595 +0x1ce\n\ngoroutine 27 [syscall]:\nsyscall.Syscall(0x4a, 0xc, 0x0, 0x0, 0xc42008f1b0, 0xc420054d80, 0x18)\n\t/snap/go/1473/src/syscall/asm_linux_amd64.s:18 +0x5\nsyscall.Fsync(0xc, 0x995828, 0xc42030e280)\n\t/snap/go/1473/src/syscall/zsyscall_linux_amd64.go:466 +0x40\ninternal/poll.(FD).Fsync(0xc42030e280, 0x0, 0x0)\n\t/snap/go/1473/src/internal/poll/fd_posix.go:56 +0x7e\nos.(File).Sync(0xc42030a070, 0x0, 0x0)\n\t/snap/go/1473/src/os/file_posix.go:127 +0x4a\ngo-template-2/logger.writeLogIntoFile(0xc4200288c0, 0x45, 0xc42030a070)\n\t/home/inverno/go_projects/src/go-template-2/logger/logger.go:310 +0x32\ngo-template-2/logger.LogFileInit.func1()\n\t/home/inverno/go_projects/src/go-template-2/logger/logger.go:258 +0x57a\ncreated by go-template-2/logger.LogFileInit\n\t/home/inverno/go_projects/src/go-template-2/logger/logger.go:249 +0x35\n\ngoroutine 63 [IO wait]:\ninternal/poll.runtime_pollWait(0x7f912a402d60, 0x72, 0xc4200539a8)\n\t/snap/go/1473/src/runtime/netpoll.go:173 +0x57\ninternal/poll.(pollDesc).wait(0xc420304218, 0x72, 0xffffffffffffff00, 0x9d5f00, 0xbf96e8)\n\t/snap/go/1473/src/internal/poll/fd_poll_runtime.go:85 +0x9b\ninternal/poll.(pollDesc).waitRead(0xc420304218, 0xc420374000, 0x1000, 0x1000)\n\t/snap/go/1473/src/internal/poll/fd_poll_runtime.go:90 +0x3d\ninternal/poll.(FD).Read(0xc420304200, 0xc420374000, 0x1000, 0x1000, 0x0, 0x0, 0x0)\n\t/snap/go/1473/src/internal/poll/fd_unix.go:157 +0x17d\nnet.(netFD).Read(0xc420304200, 0xc420374000, 0x1000, 0x1000, 0x454280, 0xc420000180, 0x4)\n\t/snap/go/1473/src/net/fd_unix.go:202 +0x4f\nnet.(conn).Read(0xc42030a060, 0xc420374000, 0x1000, 0x1000, 0x0, 0x0, 0x0)\n\t/snap/go/1473/src/net/net.go:176 +0x6a\nnet/http.(persistConn).Read(0xc42036e120, 0xc420374000, 0x1000, 0x1000, 0xc420053b98, 0x405305, 0xc420354060)\n\t/snap/go/1473/src/net/http/transport.go:1453 +0x136\nbufio.(Reader).fill(0xc4202f67e0)\n\t/snap/go/1473/src/bufio/bufio.go:100 +0x11e\nbufio.(Reader).Peek(0xc4202f67e0, 0x1, 0x0, 0x0, 0x0, 0xc4203203c0, 0x0)\n\t/snap/go/1473/src/bufio/bufio.go:132 +0x3a\nnet/http.(persistConn).readLoop(0xc42036e120)\n\t/snap/go/1473/src/net/http/transport.go:1601 +0x185\ncreated by net/http.(Transport).dialConn\n\t/snap/go/1473/src/net/http/transport.go:1237 +0x95a\n\ngoroutine 64 [select]:\nnet/http.(persistConn).writeLoop(0xc42036e120)\n\t/snap/go/1473/src/net/http/transport.go:1822 +0x14b\ncreated by net/http.(Transport).dialConn\n\t/snap/go/1473/src/net/http/transport.go:1238 +0x97f\n\ngoroutine 28 [chan receive]:\nmain.main.func1(0xc420217a70, 0xc4200da6e0, 0xc4203a4000, 0xc4202f4040, 0xc4202fa080, 0xc420217a80, 0xc4201fce40, 0xc4201fce50)\n\t/home/inverno/go_projects/src/go-template-2/main.go:393 +0xc8\ncreated by main.main\n\t/home/inverno/go_projects/src/go-template-2/main.go:388 +0x224b\n\ngoroutine 73 [select]:\ngo-template-2/emp-go-cron.(CronType).StartCron.func1(0xc4202fa080)\n\t/home/inverno/go_projects/src/go-template-2/emp-go-cron/emp-go-cron.go:62 +0x132\ncreated by go-template-2/emp-go-cron.(CronType).StartCron\n\t/home/inverno/go_projects/src/go-template-2/emp-go-cron/emp-go-cron.go:60 +0x55\n\ngoroutine 74 [select, locked to thread]:\nruntime.gopark(0x9960b8, 0x0, 0x96f230, 0x6, 0x18, 0x1)\n\t/snap/go/1473/src/runtime/proc.go:291 +0x11a\nruntime.selectgo(0xc420289f50, 0xc4203205a0)\n\t/snap/go/1473/src/runtime/select.go:392 +0xe50\nruntime.ensureSigM.func1()\n\t/snap/go/1473/src/runtime/signal_unix.go:549 +0x1f4\nruntime.goexit()\n\t/snap/go/1473/src/runtime/asm_amd64.s:2361 +0x1\n\ngoroutine 98 [runnable]:\nnet/http.(connReader).backgroundRead(0xc4202b0ed0)\n\t/snap/go/1473/src/net/http/server.go:667\ncreated by net/http.(connReader).startBackgroundRead\n\t/snap/go/1473/src/net/http/server.go:664 +0xce\n\n"}

How I may to catch with panic using panicwrap?