Closed chuck-g closed 5 years ago
There's not a huge amount of ways to get Url.parse
to throw an exception (e.g. "somethingBogus"
would return a RelativeUrl
), but I do take your point!
I'm very happy to add a Url.parseOption
method. Possibly also a Url.parseTry
that returns a Try[Url]
, because the exception thrown from an invalid URL does contain useful information such as which character was the first unexpected character.
What do you think?
Thanks again for raising this. It's now released under version 1.4.0
. Let me know if you need anything else!
That's fantastic, and a really quick turnaround! It turned out to be quite a bit more invasive than I'd have thought, but thanks for your effort.
@GitCash send .01 bch to @theon
Hey theon, user chuck-g tipped you 10000 bits in Bitcoin Cash ( ~ $5.13 ).
You can also add the "thumbs down" reaction to chuck-g's comment above to prevent future tips.
I was surprised that the
Url.parse()
method didn't return an Option or Either, as this is a potentially error-prone operation, then I foundUrlParser.getOrThrow()
which explains the unwrapped return type. Instead of doing this and making the caller handle the exception, it would be better IMHO to return anOption[Url]
orEither[Url]
. You could also do this in a new method calledUrl.parseOption
if you wanted to maintain current code.Code Example: