jackc/pgx · error
invalid net.IPNet
Error message
invalid net.IPNet
What it means
netIPNetWrapper.NetipPrefixValue guard: the stored net.IPNet holds an IP byte slice of a length netip.AddrFromSlice cannot interpret (not 4 or 16 bytes, e.g. an empty or malformed IP). The invalid IP contents inside the net.IPNet value are the faulty input.
Solutions
- Ensure the net.IPNet was built from a valid IPv4/IPv6 address (use net.ParseCIDR)
- Store and pass netip.Prefix directly instead of net.IPNet
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at pgtype/builtin_wrappers.go:534 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of jackc/pgx@ec1a0befd2 (2026-08-04).
Data as JSON: /api/errors/9e21563399b8b87f.
Report an issue: GitHub.
Appendix: source
Thrown at pgtype/builtin_wrappers.go:534
type netIPNetWrapper net.IPNet
func (w *netIPNetWrapper) ScanNetipPrefix(v netip.Prefix) error {
if !v.IsValid() {
return fmt.Errorf("cannot scan NULL into *net.IPNet")
}
*w = netIPNetWrapper{
IP: v.Addr().AsSlice(),
Mask: net.CIDRMask(v.Bits(), v.Addr().BitLen()),
}
return nil
}
func (w netIPNetWrapper) NetipPrefixValue() (netip.Prefix, error) {
ip, ok := netip.AddrFromSlice(w.IP)
if !ok {
return netip.Prefix{}, errors.New("invalid net.IPNet")
}
ones, _ := w.Mask.Size()
return netip.PrefixFrom(ip, ones), nil
}
type netIPWrapper net.IP
func (w netIPWrapper) SkipUnderlyingTypePlan() {}
func (w *netIPWrapper) ScanNetipPrefix(v netip.Prefix) error {
if !v.IsValid() {
*w = nil
return nil
}
if v.Addr().BitLen() != v.Bits() {View on GitHub (pinned to ec1a0befd2)