From d98073caa6b8aced9ea17835906e94612dc1dcec Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 2 Apr 2026 13:00:55 +0100 Subject: [PATCH] ax(node): remove banned fmt import from protocol.go Replace fmt.Sprintf/fmt.Errorf with strconv.Itoa and string concatenation; surface fmt.Errorf error paths as typed *ProtocolError values for consistent protocol error handling. Co-Authored-By: Charon --- pkg/node/protocol.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/node/protocol.go b/pkg/node/protocol.go index 969153a..a951da9 100644 --- a/pkg/node/protocol.go +++ b/pkg/node/protocol.go @@ -1,7 +1,7 @@ package node import ( - "fmt" + "strconv" ) // if pe, ok := err.(*ProtocolError); ok { log(pe.Code, pe.Message) } @@ -11,7 +11,7 @@ type ProtocolError struct { } func (e *ProtocolError) Error() string { - return fmt.Sprintf("remote error (%d): %s", e.Code, e.Message) + return "remote error (" + strconv.Itoa(e.Code) + "): " + e.Message } // handler := &ResponseHandler{} @@ -21,7 +21,7 @@ type ResponseHandler struct{} // if err := handler.ValidateResponse(resp, MsgPong); err != nil { return 0, err } func (h *ResponseHandler) ValidateResponse(resp *Message, expectedType MessageType) error { if resp == nil { - return fmt.Errorf("nil response") + return &ProtocolError{Code: ErrCodeUnknown, Message: "nil response"} } // Check for error response @@ -35,7 +35,7 @@ func (h *ResponseHandler) ValidateResponse(resp *Message, expectedType MessageTy // Check expected type if resp.Type != expectedType { - return fmt.Errorf("unexpected response type: expected %s, got %s", expectedType, resp.Type) + return &ProtocolError{Code: ErrCodeInvalidMessage, Message: "unexpected response type: expected " + string(expectedType) + ", got " + string(resp.Type)} } return nil @@ -50,7 +50,7 @@ func (h *ResponseHandler) ParseResponse(resp *Message, expectedType MessageType, if target != nil { if err := resp.ParsePayload(target); err != nil { - return fmt.Errorf("failed to parse %s payload: %w", expectedType, err) + return &ProtocolError{Code: ErrCodeInvalidMessage, Message: "failed to parse " + string(expectedType) + " payload: " + err.Error()} } }