jackc/pgx · error
invalid net.IP
Error message
invalid net.IP
What it means
netIPWrapper.NetipPrefixValue guard: the wrapped net.IP byte slice has a length netip.AddrFromSlice rejects (not 4 or 16 bytes — e.g. a nil/empty or corrupted IP). The invalid net.IP contents are the faulty input.
Solutions
- Build the net.IP via net.ParseIP or net.IPv4 so it has a canonical length
- Prefer netip.Addr as the parameter/scan type altogether
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at pgtype/builtin_wrappers.go:567 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/3906c2db5566b183.
Report an issue: GitHub.
Appendix: source
Thrown at pgtype/builtin_wrappers.go:567
return nil
}
if v.Addr().BitLen() != v.Bits() {
return fmt.Errorf("cannot scan %v to *net.IP", v)
}
*w = netIPWrapper(v.Addr().AsSlice())
return nil
}
func (w netIPWrapper) NetipPrefixValue() (netip.Prefix, error) {
if w == nil {
return netip.Prefix{}, nil
}
addr, ok := netip.AddrFromSlice([]byte(w))
if !ok {
return netip.Prefix{}, errors.New("invalid net.IP")
}
return netip.PrefixFrom(addr, addr.BitLen()), nil
}
type netipPrefixWrapper netip.Prefix
func (w *netipPrefixWrapper) ScanNetipPrefix(v netip.Prefix) error {
*w = netipPrefixWrapper(v)
return nil
}
func (w netipPrefixWrapper) NetipPrefixValue() (netip.Prefix, error) {
return netip.Prefix(w), nil
}
type netipAddrWrapper netip.Addr
View on GitHub (pinned to ec1a0befd2)