How to know the deeper go-grpc error's name and detect it? Does Go 1.13 helpful?

36 views
Skip to first unread message

dlin

unread,
Nov 13, 2019, 12:20:53 AM11/13/19
to golang-nuts
I'm use go-grpc as communication between client & server program.

When the server killed by manual, the client will get an error, I'm trying to know that situation.

Here is some client code,

 36 var check = func(err error) {
 37         if err != nil {
 38                 panic(err)
 39         }
 40 }
...
145                         } else if err != nil {
146                                 log.Println(fmt.Errorf("decompress: %w\n", err))
147                                 st := conn.GetState()
148                                 if st == connectivity.TransientFailure {  
149                                         log.Println("server may down")
150                                         break
151                                 }
152                                 log.Println("Err: grpc code:", grpc.Code(err),
153                                         "state:", st)
154                                 check(err)
155                         }


panic: rpc error: code = Unavailable desc = transport is closing   // <-- output of line 146

goroutine 1 [running]:
main.glob..func1(0xc47280, 0xc0002060a0)
        /home/rt/cmd/rt_cmd/rt_cmd.go:38 +0x6f
main.main()
        /home/rt/cmd/rt_cmd/rt_cmd.go:153 +0x1537
[guest@tradevm tmp]$ ./rt_cmd -log /mnt/tmp/rt_cmd_f.log :8003 m all
panic: rpc error: code = Unavailable desc = transport is closing

goroutine 1 [running]:
main.glob..func1(0xc47560, 0xc0000ca5f0)
        /home//rt/cmd/rt_cmd/rt_cmd.go:38 +0x6f
main.main()
        /home/dlin/prj/trade.2019rt/f/opt/tools/rt/cmd/rt_cmd/rt_cmd.go:154 +0x15e0

I found it is not easy for me to figure out which error in the output of line 146.

Does any new Go 1.13 Errors functions can help?
Reply all
Reply to author
Forward
0 new messages