Improve code readability in client stream frame handlers

- Extract stream IDs before logging calls for better readability
- Remove unnecessary anonymous functions
- Address code review feedback

Co-authored-by: dalbodeule <11470513+dalbodeule@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-12-09 14:46:00 +00:00
parent 56916c75f4
commit 446a265fa2

View File

@@ -241,25 +241,23 @@ func (p *ClientProxy) StartLoop(ctx context.Context, sess dtls.Session) error {
case protocol.MessageTypeStreamData: case protocol.MessageTypeStreamData:
// StreamData received at top level (not expected, should be consumed by handleStreamRequest) // StreamData received at top level (not expected, should be consumed by handleStreamRequest)
// This can happen if frames arrive out of order or if there's a protocol mismatch // This can happen if frames arrive out of order or if there's a protocol mismatch
log.Warn("received unexpected stream_data at top level, ignoring", logging.Fields{ streamID := "unknown"
"stream_id": func() string {
if env.StreamData != nil { if env.StreamData != nil {
return string(env.StreamData.ID) streamID = string(env.StreamData.ID)
} }
return "unknown" log.Warn("received unexpected stream_data at top level, ignoring", logging.Fields{
}(), "stream_id": streamID,
}) })
continue continue
case protocol.MessageTypeStreamClose: case protocol.MessageTypeStreamClose:
// StreamClose received at top level (not expected, should be consumed by handleStreamRequest) // StreamClose received at top level (not expected, should be consumed by handleStreamRequest)
// This can happen if frames arrive out of order or if there's a protocol mismatch // This can happen if frames arrive out of order or if there's a protocol mismatch
log.Warn("received unexpected stream_close at top level, ignoring", logging.Fields{ streamID := "unknown"
"stream_id": func() string {
if env.StreamClose != nil { if env.StreamClose != nil {
return string(env.StreamClose.ID) streamID = string(env.StreamClose.ID)
} }
return "unknown" log.Warn("received unexpected stream_close at top level, ignoring", logging.Fields{
}(), "stream_id": streamID,
}) })
continue continue
default: default: