{"record":{"id":"ae2c92efafada2e4","repo":"jackc/pgx","slug":"unable-to-encode-v-ae2c92","errorCode":null,"errorMessage":"unable to encode %v","messagePattern":"unable to encode (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pgtype/multirange.go","lineNumber":113,"sourceCode":"\tbuf = append(buf, '{')\n\n\tvar encodePlan EncodePlan\n\tvar lastElemType reflect.Type\n\tinElemBuf := make([]byte, 0, 32)\n\tfor i := range elementCount {\n\t\tif i > 0 {\n\t\t\tbuf = append(buf, ',')\n\t\t}\n\n\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","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/pgtype/multirange.go#L95-L131","documentation":"When encoding a multirange to text, the encoder reflects over each element and re-plans the element's encode step whenever the element's Go type changes. This guard fires when no encode plan can be found for an element — the element's type is not encodable to the multirange's element type OID (e.g. a Go type not registered for the underlying range subtype).","triggerScenarios":"Thrown at pgtype/multirange.go:113 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure all elements share a Go type registered for the multirange's element type via RegisterDefaultPgType","Scan into a typed Multirange[Range[T]] instead of a mixed-type slice","Remove unsupported element types from the slice before encoding"],"exampleFix":null,"handlingStrategy":"type-guard","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"}