Skip to content

Commit 8ab15ef

Browse files
authored
better panic debug strs (#2524)
1 parent 6c5c82f commit 8ab15ef

File tree

5 files changed

+29
-16
lines changed

5 files changed

+29
-16
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/web/ws.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,13 @@ func getStringFromMap(jmsg map[string]any, key string) string {
8181

8282
func processWSCommand(jmsg map[string]any, outputCh chan any, rpcInputCh chan []byte) {
8383
var rtnErr error
84+
var cmdType string
8485
defer func() {
85-
panicErr := panichandler.PanicHandler("processWSCommand", recover())
86+
panicCtx := "processWSCommand"
87+
if cmdType != "" {
88+
panicCtx = fmt.Sprintf("processWSCommand:%s", cmdType)
89+
}
90+
panicErr := panichandler.PanicHandler(panicCtx, recover())
8691
if panicErr != nil {
8792
rtnErr = panicErr
8893
}
@@ -97,6 +102,7 @@ func processWSCommand(jmsg map[string]any, outputCh chan any, rpcInputCh chan []
97102
rtnErr = fmt.Errorf("cannot parse wscommand: %v", err)
98103
return
99104
}
105+
cmdType = wsCommand.GetWSCommand()
100106
switch cmd := wsCommand.(type) {
101107
case *webcmd.SetBlockTermSizeWSCommand:
102108
data := wshrpc.CommandBlockInputData{
@@ -137,6 +143,9 @@ func processWSCommand(jmsg map[string]any, outputCh chan any, rpcInputCh chan []
137143
if rpcMsg == nil {
138144
return
139145
}
146+
if rpcMsg.Command != "" {
147+
cmdType = fmt.Sprintf("%s:%s", cmdType, rpcMsg.Command)
148+
}
140149
msgBytes, err := json.Marshal(rpcMsg)
141150
if err != nil {
142151
// this really should never fail since we just unmarshalled this value

pkg/wshutil/wshproxy.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func (p *WshRpcProxy) sendResponseError(msg RpcMessage, sendErr error) {
6666
Error: sendErr.Error(),
6767
}
6868
respBytes, _ := json.Marshal(resp)
69-
p.SendRpcMessage(respBytes)
69+
p.SendRpcMessage(respBytes, "resp-error")
7070
}
7171

7272
func (p *WshRpcProxy) sendAuthenticateResponse(msg RpcMessage, routeId string) {
@@ -80,7 +80,7 @@ func (p *WshRpcProxy) sendAuthenticateResponse(msg RpcMessage, routeId string) {
8080
Data: wshrpc.CommandAuthenticateRtnData{RouteId: routeId},
8181
}
8282
respBytes, _ := json.Marshal(resp)
83-
p.SendRpcMessage(respBytes)
83+
p.SendRpcMessage(respBytes, "auth-resp")
8484
}
8585

8686
func (p *WshRpcProxy) sendAuthenticateTokenResponse(msg RpcMessage, entry *shellutil.TokenSwapEntry) {
@@ -99,7 +99,7 @@ func (p *WshRpcProxy) sendAuthenticateTokenResponse(msg RpcMessage, entry *shell
9999
},
100100
}
101101
respBytes, _ := json.Marshal(resp)
102-
p.SendRpcMessage(respBytes)
102+
p.SendRpcMessage(respBytes, "auth-token-resp")
103103
}
104104

105105
func validateRpcContextFromAuth(newCtx *wshrpc.RpcContext) (string, error) {
@@ -249,9 +249,13 @@ func (p *WshRpcProxy) HandleAuthentication() (*wshrpc.RpcContext, error) {
249249
}
250250

251251
// TODO: Figure out who is sending to closed routes and why we're not catching it
252-
func (p *WshRpcProxy) SendRpcMessage(msg []byte) {
252+
func (p *WshRpcProxy) SendRpcMessage(msg []byte, debugStr string) {
253253
defer func() {
254-
panichandler.PanicHandler("WshRpcProxy.SendRpcMessage", recover())
254+
panicCtx := "WshRpcProxy.SendRpcMessage"
255+
if debugStr != "" {
256+
panicCtx = fmt.Sprintf("%s:%s", panicCtx, debugStr)
257+
}
258+
panichandler.PanicHandler(panicCtx, recover())
255259
}()
256260
p.ToRemoteCh <- msg
257261
}

pkg/wshutil/wshrouter.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func (router *WshRouter) SendEvent(routeId string, event wps.WaveEvent) {
122122
// nothing to do
123123
return
124124
}
125-
rpc.SendRpcMessage(msgBytes)
125+
rpc.SendRpcMessage(msgBytes, "eventrecv")
126126
}
127127

128128
func (router *WshRouter) handleNoRoute(msg RpcMessage) {
@@ -173,7 +173,7 @@ func (router *WshRouter) handleAnnounceMessage(msg RpcMessage, input msgAndRoute
173173
// if we don't (we are the terminal router), then add it to our announced route map
174174
upstream := router.GetUpstreamClient()
175175
if upstream != nil {
176-
upstream.SendRpcMessage(input.msgBytes)
176+
upstream.SendRpcMessage(input.msgBytes, "announce-upstream")
177177
return
178178
}
179179
if msg.Source == input.fromRouteId {
@@ -201,12 +201,12 @@ func (router *WshRouter) getAnnouncedRoute(routeId string) string {
201201
func (router *WshRouter) sendRoutedMessage(msgBytes []byte, routeId string) bool {
202202
rpc := router.GetRpc(routeId)
203203
if rpc != nil {
204-
rpc.SendRpcMessage(msgBytes)
204+
rpc.SendRpcMessage(msgBytes, "route")
205205
return true
206206
}
207207
upstream := router.GetUpstreamClient()
208208
if upstream != nil {
209-
upstream.SendRpcMessage(msgBytes)
209+
upstream.SendRpcMessage(msgBytes, "route-upstream")
210210
return true
211211
} else {
212212
// we are the upstream, so consult our announced routes map
@@ -216,7 +216,7 @@ func (router *WshRouter) sendRoutedMessage(msgBytes []byte, routeId string) bool
216216
log.Printf("[router] no rpc for route id %q\n", routeId)
217217
return false
218218
}
219-
rpc.SendRpcMessage(msgBytes)
219+
rpc.SendRpcMessage(msgBytes, "route-local")
220220
return true
221221
}
222222
}
@@ -321,7 +321,7 @@ func (router *WshRouter) RegisterRoute(routeId string, rpc AbstractRpcClient, sh
321321
if shouldAnnounce && !alreadyExists && router.GetUpstreamClient() != nil {
322322
announceMsg := RpcMessage{Command: wshrpc.Command_RouteAnnounce, Source: routeId}
323323
announceBytes, _ := json.Marshal(announceMsg)
324-
router.GetUpstreamClient().SendRpcMessage(announceBytes)
324+
router.GetUpstreamClient().SendRpcMessage(announceBytes, "route-announce")
325325
}
326326
for {
327327
msgBytes, ok := rpc.RecvRpcMessage()

pkg/wshutil/wshrpc.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type ServerImpl interface {
4040
}
4141

4242
type AbstractRpcClient interface {
43-
SendRpcMessage(msg []byte)
43+
SendRpcMessage(msg []byte, debugStr string)
4444
RecvRpcMessage() ([]byte, bool) // blocking
4545
}
4646

@@ -103,7 +103,7 @@ func GetRpcResponseHandlerFromContext(ctx context.Context) *RpcResponseHandler {
103103
return rtn.(*RpcResponseHandler)
104104
}
105105

106-
func (w *WshRpc) SendRpcMessage(msg []byte) {
106+
func (w *WshRpc) SendRpcMessage(msg []byte, debugStr string) {
107107
w.InputCh <- msg
108108
}
109109

0 commit comments

Comments
 (0)