{"record":{"id":"583aeda68a0bf542","repo":"jackc/pgx","slug":"multirange-cannot-contain-null-element","errorCode":null,"errorMessage":"multirange cannot contain NULL element","messagePattern":"multirange cannot contain NULL element","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pgtype/multirange.go","lineNumber":123,"sourceCode":"\t\telem := multirange.Index(i)\n\t\tvar elemBuf []byte\n\t\tif elem != nil {\n\t\t\telemType := reflect.TypeOf(elem)\n\t\t\tif lastElemType != elemType {\n\t\t\t\tlastElemType = elemType\n\t\t\t\tencodePlan = p.m.PlanEncode(p.ac.ElementType.OID, TextFormatCode, elem)\n\t\t\t\tif encodePlan == nil {\n\t\t\t\t\treturn nil, fmt.Errorf(\"unable to encode %v\", multirange.Index(i))\n\t\t\t\t}\n\t\t\t}\n\t\t\telemBuf, err = encodePlan.Encode(elem, inElemBuf)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t}\n\n\t\tif elemBuf == nil {\n\t\t\treturn nil, fmt.Errorf(\"multirange cannot contain NULL element\")\n\t\t} else {\n\t\t\tbuf = append(buf, elemBuf...)\n\t\t}\n\t}\n\n\tbuf = append(buf, '}')\n\n\treturn buf, nil\n}\n\ntype encodePlanMultirangeCodecBinary struct {\n\tac  *MultirangeCodec\n\tm   *Map\n\toid uint32\n}\n\nfunc (p *encodePlanMultirangeCodecBinary) Encode(value any, buf []byte) (newBuf []byte, err error) {\n\tmultirange := value.(MultirangeGetter)","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/pgtype/multirange.go#L105-L141","documentation":"While encoding a multirange to text, each element is encoded into a buffer; a nil buffer after encoding means the element was itself SQL NULL. Since a multirange is a set of non-null ranges, this guard rejects NULL elements outright.","triggerScenarios":"Thrown at pgtype/multirange.go:123 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Filter nil/invalid elements out of the slice before encoding","Replace NULL elements with an explicit empty or unbounded range if that is the intended semantics"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"ec1a0befd22592cffffdeeb0a50311b506372f4c","analyzedAt":"2026-08-04T22:52:11.263Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}