{"record":{"id":"39f64572b26566f4","repo":"jackc/pgx","slug":"cannot-scan-into-non-pointer-or-nil-destinations","errorCode":null,"errorMessage":"cannot scan into non-pointer or nil destinations %T","messagePattern":"cannot scan into non-pointer or nil destinations %T","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pgtype/json.go","lineNumber":216,"sourceCode":"\nfunc (s *scanPlanJSONToJSONUnmarshal) Scan(src []byte, dst any) error {\n\tif src == nil {\n\t\tdstValue := reflect.ValueOf(dst)\n\t\tif dstValue.Kind() == reflect.Pointer {\n\t\t\tel := dstValue.Elem()\n\t\t\tswitch el.Kind() {\n\t\t\tcase reflect.Pointer, reflect.Slice, reflect.Map, reflect.Interface:\n\t\t\t\tel.Set(reflect.Zero(el.Type()))\n\t\t\t\treturn nil\n\t\t\t}\n\t\t}\n\n\t\treturn fmt.Errorf(\"cannot scan NULL into %T\", dst)\n\t}\n\n\tv := reflect.ValueOf(dst)\n\tif v.Kind() != reflect.Pointer || v.IsNil() {\n\t\treturn fmt.Errorf(\"cannot scan into non-pointer or nil destinations %T\", dst)\n\t}\n\n\telem := v.Elem()\n\telem.Set(reflect.Zero(elem.Type()))\n\n\treturn s.unmarshal(src, dst)\n}\n\nfunc (c *JSONCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error) {\n\tif src == nil {\n\t\treturn nil, nil\n\t}\n\n\tdstBuf := make([]byte, len(src))\n\tcopy(dstBuf, src)\n\treturn dstBuf, nil\n}\n","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/pgtype/json.go#L198-L234","documentation":"This guard in the JSONUnmarshal scan plan verifies that the destination passed to Scan is a non-nil Go pointer before reflection is used to set it. It fires when dst is not a pointer at all, or is a nil pointer, making assignment impossible; the offending destination type is included in the message.","triggerScenarios":"Thrown at pgtype/json.go:216 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Always pass the address of the target variable (e.g. &myValue) to Scan","Ensure the destination pointer is initialized and non-nil before scanning","Check the variable declaration for a missing & operator"],"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"}