{"record":{"id":"f047ba1c8c308b04","repo":"jackc/pgx","slug":"cannot-scan-v-to-net-ip","errorCode":null,"errorMessage":"cannot scan %v to *net.IP","messagePattern":"cannot scan (.+?) to \\*net\\.IP","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pgtype/builtin_wrappers.go","lineNumber":553,"sourceCode":"\t}\n\n\tones, _ := w.Mask.Size()\n\n\treturn netip.PrefixFrom(ip, ones), nil\n}\n\ntype netIPWrapper net.IP\n\nfunc (w netIPWrapper) SkipUnderlyingTypePlan() {}\n\nfunc (w *netIPWrapper) ScanNetipPrefix(v netip.Prefix) error {\n\tif !v.IsValid() {\n\t\t*w = nil\n\t\treturn nil\n\t}\n\n\tif v.Addr().BitLen() != v.Bits() {\n\t\treturn fmt.Errorf(\"cannot scan %v to *net.IP\", v)\n\t}\n\n\t*w = netIPWrapper(v.Addr().AsSlice())\n\treturn nil\n}\n\nfunc (w netIPWrapper) NetipPrefixValue() (netip.Prefix, error) {\n\tif w == nil {\n\t\treturn netip.Prefix{}, nil\n\t}\n\n\taddr, ok := netip.AddrFromSlice([]byte(w))\n\tif !ok {\n\t\treturn netip.Prefix{}, errors.New(\"invalid net.IP\")\n\t}\n\n\treturn netip.PrefixFrom(addr, addr.BitLen()), nil\n}","sourceCodeStart":535,"sourceCodeEnd":571,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/pgtype/builtin_wrappers.go#L535-L571","documentation":"Returned by netIPWrapper.ScanNetipPrefix when the prefix's bit count is less than the address bit length — i.e. the netip.Prefix carries subnet mask information that would be lost, because net.IP stores only a bare address with no mask.","triggerScenarios":"Thrown at pgtype/builtin_wrappers.go:553 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Scan into netip.Prefix or net.IPNet to preserve the network mask","Store the value as inet with /32 or /128 so no mask information exists","Truncate the address to its prefix in the query before scanning"],"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"}