ip4s
ip4s copied to clipboard
Alternative version of Host.fromString that returns error message?
I recently had a problem where Host.fromString
failed due to an underscore character (which seems reasonable). Could you provide an alternate version, eg. Host.fromStringEither
which explains why host parsing failed?
We could follow the precedent from scodec-bits and add def fromStringDescriptive(s: String): Either[String, Host]
. We'd need to do that for a bunch of types though, not just Host
. We'd also need to ensure the error messages are useful and not just stuff like ""foo_bar" is not a valid ip address, hostname, or IDN"
I had a go at implementing this and found it difficult. Since a host is one of three things, at least two of them will fail, so if all three fail (eg. something that's a hostname but an invalid one) then it's hard to know which one it was supposed to be.
Something more specific would fix this, but then there'd be a proliferation of methods
HostName.fromStringDescriptive
Ipv4Address.fromStringDescriptive
etc.