{"record":{"id":"56e3b91689b2553f","repo":"fatedier/frp","slug":"unsupported-udp-packet-codec-q","errorCode":null,"errorMessage":"unsupported UDP packet codec %q","messagePattern":"unsupported UDP packet codec %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/msg/udp_binary.go","lineNumber":333,"sourceCode":"}\n\n// NewUDPPacketReadWriter selects the negotiated packet codec without changing\n// the framing or codecs used by non-UDP messages on the work connection.\nfunc NewUDPPacketReadWriter(rw io.ReadWriter, wireProtocol, udpPacketCodec string) (ReadWriter, error) {\n\tswitch wireProtocol {\n\tcase \"\", wire.ProtocolV1:\n\t\tif udpPacketCodec != \"\" {\n\t\t\treturn nil, fmt.Errorf(\"UDP packet codec %q requires wire protocol v2\", udpPacketCodec)\n\t\t}\n\t\treturn NewV1ReadWriter(rw), nil\n\tcase wire.ProtocolV2:\n\t\tswitch udpPacketCodec {\n\t\tcase \"\":\n\t\t\treturn NewV2ReadWriter(rw), nil\n\t\tcase wire.UDPPacketCodecBinary:\n\t\t\treturn NewV2BinaryUDPPacketReadWriter(rw), nil\n\t\tdefault:\n\t\t\treturn nil, fmt.Errorf(\"unsupported UDP packet codec %q\", udpPacketCodec)\n\t\t}\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"unsupported wire protocol %q\", wireProtocol)\n\t}\n}\n","sourceCodeStart":315,"sourceCodeEnd":339,"githubUrl":"https://github.com/fatedier/frp/blob/6c8a8d0a97d03b44e9528d30b30c70cb9d61b405/pkg/msg/udp_binary.go#L315-L339","documentation":"NewUDPPacketReadWriter rejects a udpPacketCodec string that is neither empty nor \"binary\" (wire.UDPPacketCodecBinary). Only two codec states exist in the v2 branch: default JSON packets or the binary codec; anything else is a configuration typo or a value from a different frp version.","triggerScenarios":"Calling NewUDPPacketReadWriter(rw, wire.ProtocolV2, \"bin\"), \"msgpack\", \"legacy\", or any unrecognized string; typically from hand-written config or a config field populated by user input without validation.","commonSituations":"Typo in udpPacketCodec config; docs/examples from another version naming a codec that this release does not implement; dynamic config generation interpolating an unvalidated value.","solutions":["Use only \"\" (default JSON) or \"binary\" for udpPacketCodec with wire protocol v2.","Validate user-supplied codec strings against wire.UDPPacketCodecBinary before constructing the read writer.","Check the exact constant: wire.UDPPacketCodecBinary."],"exampleFix":"// before\nrw, err := msg.NewUDPPacketReadWriter(conn, wire.ProtocolV2, \"bin\")\n\n// after\nrw, err := msg.NewUDPPacketReadWriter(conn, wire.ProtocolV2, wire.UDPPacketCodecBinary)","handlingStrategy":"validation","validationCode":"switch udpPacketCodec {\ncase \"\", wire.UDPPacketCodecBinary:\ndefault:\n\treturn fmt.Errorf(\"unsupported UDP packet codec %q\", udpPacketCodec)\n}","typeGuard":"func isSupportedUDPPacketCodec(c string) bool {\n\treturn c == \"\" || c == wire.UDPPacketCodecBinary\n}","tryCatchPattern":null,"preventionTips":["Restrict config values to the constant set; reject free-form input at config load.","Cross-check codec names against the wire package when upgrading frp versions."],"tags":["config","validation","udp","frp"],"backgroundTag":null,"analyzedSha":"6c8a8d0a97d03b44e9528d30b30c70cb9d61b405","analyzedAt":"2026-08-15T06:53:27.215Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}