{"record":{"id":"39f1448bdc36dd3d","repo":"cloudflare/cloudflared","slug":"datagram-response-message-is-an-invalid-size","errorCode":null,"errorMessage":"datagram response message is an invalid size","messagePattern":"datagram response message is an invalid size","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"quic/v3/datagram_errors.go","lineNumber":14,"sourceCode":"package v3\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n)\n\nvar (\n\tErrInvalidDatagramType                 error = errors.New(\"invalid datagram type expected\")\n\tErrDatagramHeaderTooSmall              error = fmt.Errorf(\"datagram should have at least %d byte\", datagramTypeLen)\n\tErrDatagramPayloadTooLarge             error = errors.New(\"payload length is too large to be bundled in datagram\")\n\tErrDatagramPayloadHeaderTooSmall       error = errors.New(\"payload length is too small to fit the datagram header\")\n\tErrDatagramPayloadInvalidSize          error = errors.New(\"datagram provided is an invalid size\")\n\tErrDatagramResponseMsgInvalidSize      error = errors.New(\"datagram response message is an invalid size\")\n\tErrDatagramResponseInvalidSize         error = errors.New(\"datagram response is an invalid size\")\n\tErrDatagramResponseMsgTooLargeMaximum  error = fmt.Errorf(\"datagram response error message length exceeds the length of the datagram maximum: %d\", maxResponseErrorMessageLen)\n\tErrDatagramResponseMsgTooLargeDatagram error = fmt.Errorf(\"datagram response error message length exceeds the length of the provided datagram\")\n\tErrDatagramICMPPayloadTooLarge         error = fmt.Errorf(\"datagram icmp payload exceeds %d bytes\", maxICMPPayloadLen)\n\tErrDatagramICMPPayloadMissing          error = errors.New(\"datagram icmp payload is missing\")\n)\n\nfunc wrapMarshalErr(err error) error {\n\treturn fmt.Errorf(\"datagram marshal error: %w\", err)\n}\n\nfunc wrapUnmarshalErr(err error) error {\n\treturn fmt.Errorf(\"datagram unmarshal error: %w\", err)\n}\n","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/cloudflare/cloudflared/blob/2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f/quic/v3/datagram_errors.go#L1-L29","documentation":"ErrDatagramResponseMsgInvalidSize is returned by UDPSessionRegistrationResponseDatagram.MarshalBinary when the ErrorMsg field exceeds maxResponseErrorMessageLen. The response datagram format reserves a fixed-size field for the error message, so longer messages cannot be encoded. The library refuses to marshal rather than silently truncating the message.","triggerScenarios":"Marshaling a UDPSessionRegistrationResponseDatagram whose ErrorMsg string is longer than maxResponseErrorMessageLen bytes.","commonSituations":"Propagating raw origin/registration errors (long Go error strings, wrapped chain text) into the response ErrorMsg without trimming; embedding stack traces or URLs in ErrorMsg.","solutions":["Truncate ErrorMsg to maxResponseErrorMessageLen bytes before setting it on the datagram","Replace long error text with a short reason code and log the full message locally instead","Use errors.Is(err, v3.ErrDatagramResponseMsgInvalidSize) after MarshalBinary to catch and shorten the message"],"exampleFix":"// before\nresp := &v3.UDPSessionRegistrationResponseDatagram{ErrorMsg: veryLongErrorString}\ndata, err := resp.MarshalBinary() // -> ErrDatagramResponseMsgInvalidSize\n// after\nmsg := veryLongErrorString\nif len(msg) > maxResponseErrorMessageLen {\n    msg = msg[:maxResponseErrorMessageLen]\n}\nresp := &v3.UDPSessionRegistrationResponseDatagram{ErrorMsg: msg}\ndata, err := resp.MarshalBinary()","handlingStrategy":"validation","validationCode":"if len(errMsg) > maxResponseErrorMessageLen {\n    errMsg = errMsg[:maxResponseErrorMessageLen]\n}","typeGuard":null,"tryCatchPattern":"if _, err := resp.MarshalBinary(); errors.Is(err, v3.ErrDatagramResponseMsgInvalidSize) {\n    resp.ErrorMsg = \"error details too long\"\n    _, err = resp.MarshalBinary()\n}","preventionTips":["Truncate error strings at construction time","Send reason codes, keep long text in server logs only","Define a helper to build response datagrams with clamped messages"],"tags":["quic","datagram","response","payload-size"],"backgroundTag":"payload-too-large","analyzedSha":"2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f","analyzedAt":"2026-09-06T04:14:33.757Z","contentChangedAt":"2026-09-06T04:14:33.757Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}