pkg/net: return errors for unexpected types in IP validators
netGetIP and netGetIPCIDR silently accepted any value type,
returning zero values instead of errors. This caused net.IPCIDR
to incorrectly succeed on non-string types like integers,
and other validators like net.IP, net.IPv4, net.IPv6 to give
less informative "does not satisfy" errors without details.
Change netGetIP to return (netip.Addr, error) and netGetIPCIDR
to return an error for unexpected types. Update all callers:
IPv4, IPv6, IP, LoopbackIP, MulticastIP, InterfaceLocalMulticastIP,
LinkLocalMulticastIP, LinkLocalUnicastIP, GlobalUnicastIP,
UnspecifiedIP now return (bool, error). ToIP4, ToIP16, IPString,
AddIP, InCIDR, CompareIP, and JoinHostPort updated accordingly.
As a side effect, all error messages now include the underlying
cause from the standard library, e.g. "ParseAddr(...): IPv4 field
has value >255" rather than just "does not satisfy net.IPv4".
Fixes #3979.
Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: Ica7468aaaf87d3e9c0ad94a616ebecdec6c49d9c
Reviewed-on: https://cue.gerrithub.io/c/cue-lang/cue/+/1233776
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>