{"record":{"id":"1ab6effb9d9c18a8","repo":"jackc/pgx","slug":"upper-cannot-be-null-unless-uppertype-is-unbounded","errorCode":null,"errorMessage":"Upper cannot be NULL unless UpperType is Unbounded","messagePattern":"Upper cannot be NULL unless UpperType is Unbounded","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pgtype/range_codec.go","lineNumber":134,"sourceCode":"\t\tlowerPlan := plan.m.PlanEncode(plan.rc.ElementType.OID, BinaryFormatCode, lower)\n\t\tif lowerPlan == nil {\n\t\t\treturn nil, fmt.Errorf(\"cannot encode %v as element of range\", lower)\n\t\t}\n\n\t\tbuf, err = lowerPlan.Encode(lower, buf)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to encode %v as element of range: %w\", lower, err)\n\t\t}\n\t\tif buf == nil {\n\t\t\treturn nil, fmt.Errorf(\"Lower cannot be NULL unless LowerType is Unbounded\")\n\t\t}\n\n\t\tpgio.SetInt32(buf[sp:], int32(len(buf[sp:])-4))\n\t}\n\n\tif upperType != Unbounded {\n\t\tif upper == nil {\n\t\t\treturn nil, fmt.Errorf(\"Upper cannot be NULL unless UpperType is Unbounded\")\n\t\t}\n\n\t\tsp := len(buf)\n\t\tbuf = pgio.AppendInt32(buf, -1)\n\n\t\tupperPlan := plan.m.PlanEncode(plan.rc.ElementType.OID, BinaryFormatCode, upper)\n\t\tif upperPlan == nil {\n\t\t\treturn nil, fmt.Errorf(\"cannot encode %v as element of range\", upper)\n\t\t}\n\n\t\tbuf, err = upperPlan.Encode(upper, buf)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to encode %v as element of range: %w\", upper, err)\n\t\t}\n\t\tif buf == nil {\n\t\t\treturn nil, fmt.Errorf(\"Upper cannot be NULL unless UpperType is Unbounded\")\n\t\t}\n","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/pgtype/range_codec.go#L116-L152","documentation":"The range's upper bound is bounded (Inclusive or Exclusive) but the value returned for it is nil. The binary format reserves NULL encoding only for unbounded bounds, so the caller's RangeValuer state is inconsistent.","triggerScenarios":"Thrown at pgtype/range_codec.go:134 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set UpperType to Unbounded when the upper value is absent","Supply a non-nil upper bound for bounded ranges","Use pgtype.Range[T] to maintain consistent bound state"],"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"}