{"record":{"id":"74c8da73b1b9a112","repo":"cloudflare/cloudflared","slug":"errdatagramheadertoosmall","errorCode":"ErrDatagramHeaderTooSmall","errorMessage":"datagram should have at least %d byte","messagePattern":"datagram should have at least (.+?) byte","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"quic/v3/datagram_errors.go","lineNumber":10,"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}","sourceCodeStart":1,"sourceCodeEnd":28,"githubUrl":"https://github.com/cloudflare/cloudflared/blob/2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f/quic/v3/datagram_errors.go#L1-L28","documentation":"ErrDatagramHeaderTooSmall is a sentinel error in quic/v3/datagram_errors.go indicating that a datagram buffer is shorter than the single-byte datagram type header (datagramTypeLen). ParseDatagramType returns it when len(data) < 1, and UnmarshalBinary implementations surface it for empty or truncated inputs. It means the byte slice is too small to even identify the datagram type, so no parsing can proceed.","triggerScenarios":"Calling ParseDatagramType with an empty or nil slice; calling UnmarshalBinary on any v3 datagram type (e.g. UDPSessionRegistrationDatagram) with an empty byte slice; receiving a zero-length datagram over the session.","commonSituations":"Peer closed a stream/session and delivered an empty read; buffer-slicing math upstream chopped the header off; tests feeding []byte{} to validate error paths; a serialization bug producing empty payloads on the wire.","solutions":["Check len(data) >= datagramTypeLen (1) before calling ParseDatagramType or UnmarshalBinary.","Use errors.Is(err, v3.ErrDatagramHeaderTooSmall) to branch and skip/drop empty datagrams gracefully.","Trace where the buffer is produced; fix the length calculation that emitted a sub-header-sized slice.","Ensure the remote side always prefixes datagrams with the type byte."],"exampleFix":"// before\nerr := datagram.UnmarshalBinary(buf)\n// after\nif len(buf) < v3.DatagramTypeLen {\n    return fmt.Errorf(\"datagram too small: %d bytes\", len(buf))\n}\nerr := datagram.UnmarshalBinary(buf)\nif errors.Is(err, v3.ErrDatagramHeaderTooSmall) {\n    logger.Debug().Msg(\"dropping empty datagram\")\n    return nil\n}","handlingStrategy":"type-guard","validationCode":"if len(data) < 1 {\n    return fmt.Errorf(\"empty datagram buffer\")\n}","typeGuard":"func hasDatagramHeader(data []byte) bool {\n    return len(data) >= v3.DatagramTypeLen\n}","tryCatchPattern":"if errors.Is(err, v3.ErrDatagramHeaderTooSmall) {\n    logger.Debug().Msg(\"datagram too small to parse; skipping\")\n    return nil\n}","preventionTips":["Never call ParseDatagramType/UnmarshalBinary on empty slices; short-circuit on len(data)==0.","Check read-loop return values: empty reads often mean the session closed.","Match sentinel errors with errors.Is, not string comparison."],"tags":["quic","datagram","wire-format","protocol"],"backgroundTag":"schema-validation-failed","analyzedSha":"2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f","analyzedAt":"2026-09-06T04:14:33.757Z","contentChangedAt":"2026-09-06T04:14:33.757Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}