[BUG] FormatMessageType returns empty string for unknown type
GreenMarmot opened this issue · 3 comments
Is there an existing issue for this?
- I have searched the existing issues
Current Behavior
FormatMessageType returns the empty string for an unknown message type.
Expected Behavior
FormatMessageType should return the decimal representation of the type when the type is unknown.
Steps To Reproduce
fmt.Println(websocket.FormatMessageType(7777))
Actual output: blank line
Expected output: 7777
Anything else?
Cc @rfyiamcool
@GreenMarmot
Do you want expected value when call fmt.Println(websocket.FormatMessageType(7777))
? Currently input an unknown type, returns an empty string. 😁
I'm sorry, I don't understand your question. 😅
@rfyiamcool @GreenMarmot We can document the FormatMessageType function's expected return value through a descriptive Go doc comment
IMHO returning an empty string or the string representation of the opcode value (strconv.Itoa(input integer)
) may not convey enough information about the error condition, potentially leading to more confusion or ambiguity.
I think returning a string like "InvalidOpcode", "InvalidMessageType", "unknown opcode" , would make function's behavior more explicit and easier to handle.
Let me know your thoughts!