Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternative version of Host.fromString that returns error message? #505

Open
george-wilson-rea opened this issue Jul 11, 2023 · 2 comments

Comments

@george-wilson-rea
Copy link

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?

@mpilquist
Copy link
Member

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"

@george-wilson-rea
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants