scinfu / SwiftSoup

SwiftSoup: Pure Swift HTML Parser, with best of DOM, CSS, and jquery (Supports Linux, iOS, Mac, tvOS, watchOS)
https://scinfu.github.io/SwiftSoup/
MIT License
4.52k stars 345 forks source link

Requesting throwing alternative to body() #273

Open bjo0 opened 3 months ago

bjo0 commented 3 months ago

The signature for body() is:

func body() -> Element?

It would improve ergonomics if there was a version of this that threw, e.g.:

func body() throws -> Element

This would allow for better ergonomics at call sites that propagate errors, while not really diminishing the ergonomics for sites that want to deal in optionals, as try? is always available.

It wasn't immediately clear to me if try document.select("body") is an appropriate alternative for getting a throwing version of this.

aehlke commented 2 months ago

It sounds good but I wouldn't want to break the existing API to make this change alone and don't think it's worth adding a 2nd new function to opt into this new behavior

bjo0 commented 2 months ago

By this you mean that you include adding a case to the error enum as a breaking change?

Maybe this can go on a wishlist for the next major semver, if ever one happens?

aehlke commented 2 months ago

I mean changing it to be throwing would require everyone to update their code

I think no one is managing a wish list, this is all volunteer effort

bjo0 commented 2 months ago

I suggest making it be non-breaking from that perspective, with the existing route still offered, and maybe have it call into the throwing version with a try?.On Aug 20, 2024, at 10:28, Alex Ehlke @.***> wrote: I mean changing it to be throwing would require everyone to update their code

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>