{"record":{"id":"52aaa6e87fba2f04","repo":"jackc/pgx","slug":"cannot-scan-null-into-net-ipnet","errorCode":null,"errorMessage":"cannot scan NULL into *net.IPNet","messagePattern":"cannot scan NULL into \\*net\\.IPNet","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pgtype/builtin_wrappers.go","lineNumber":520,"sourceCode":"func (w *durationWrapper) ScanInterval(v Interval) error {\n\tif !v.Valid {\n\t\treturn fmt.Errorf(\"cannot scan NULL into *time.Interval\")\n\t}\n\n\tus := int64(v.Months)*microsecondsPerMonth + int64(v.Days)*microsecondsPerDay + v.Microseconds\n\t*w = durationWrapper(time.Duration(us) * time.Microsecond)\n\treturn nil\n}\n\nfunc (w durationWrapper) IntervalValue() (Interval, error) {\n\treturn Interval{Microseconds: int64(w) / 1000, Valid: true}, nil\n}\n\ntype netIPNetWrapper net.IPNet\n\nfunc (w *netIPNetWrapper) ScanNetipPrefix(v netip.Prefix) error {\n\tif !v.IsValid() {\n\t\treturn fmt.Errorf(\"cannot scan NULL into *net.IPNet\")\n\t}\n\n\t*w = netIPNetWrapper{\n\t\tIP:   v.Addr().AsSlice(),\n\t\tMask: net.CIDRMask(v.Bits(), v.Addr().BitLen()),\n\t}\n\n\treturn nil\n}\n\nfunc (w netIPNetWrapper) NetipPrefixValue() (netip.Prefix, error) {\n\tip, ok := netip.AddrFromSlice(w.IP)\n\tif !ok {\n\t\treturn netip.Prefix{}, errors.New(\"invalid net.IPNet\")\n\t}\n\n\tones, _ := w.Mask.Size()\n","sourceCodeStart":502,"sourceCodeEnd":538,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/pgtype/builtin_wrappers.go#L502-L538","documentation":"ScanNetipPrefix was given an invalid (zero-value, NULL) netip.Prefix while scanning into *net.IPNet, which cannot represent NULL. Null guard in netIPNetWrapper; the inet/cidr column was NULL but the destination is a non-nullable net.IPNet.","triggerScenarios":"Thrown at pgtype/builtin_wrappers.go:520 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Scan into netip.Prefix (its zero value represents NULL) or *net.IPNet","Use COALESCE with a default network in the query","Ensure the column is NOT NULL"],"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"}