ip4s icon indicating copy to clipboard operation
ip4s copied to clipboard

Alternative version of Host.fromString that returns error message?

Open george-wilson-rea opened this issue 1 year ago • 2 comments

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?

george-wilson-rea avatar Jul 11 '23 06:07 george-wilson-rea

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"

mpilquist avatar Jul 12 '23 13:07 mpilquist

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.

george-wilson-rea avatar Jul 12 '23 23:07 george-wilson-rea