mirage / ocaml-uri

RFC3986 URI parsing library for OCaml
Other
97 stars 57 forks source link

Introduce Absolute_http specialization #164

Closed torinnd closed 1 year ago

torinnd commented 1 year ago

An RFC9110-compliance specialization of a [Uri.t]

Addresses #162

avsm commented 1 year ago

Thanks! This looks good to me, some notes in no order:

talex5 commented 1 year ago

we're increasingly shifting to exception raising functions as the default, with the move towards direct-style interfaces in OCaml 5.

If you mean Eio's error handling policy then I'd like to clarify that this is for IO errors, where there is a large and unknown set of possible errors (e.g. depending on the platform). For those, you can't handle all individual errors and must usually propagate them by default, so exceptions typically make more sense.

Parsing is an interesting case. Eio.Buf_read.parse returns a result type, because it's common to want to handle parsing errors. But it wraps individual parsers that raise Failure on error, because plumbing result types through all the parsing code is slow.

This isn't my library, but this PR's choice of returning a result for the new of_uri function, and matching what the rest of the library does for of_string, seems fine to me. It would be good to document what of_string does on error, though.

dinosaure commented 1 year ago

This isn't my library, but this PR's choice of returning a result for the new of_uri function, and matching what the rest of the library does for of_string, seems fine to me. It would be good to document what of_string does on error, though.

I agree with that and ocaml-uri is relatively standalone. We should not use a wider error politic other than the one described into our website.

avsm commented 1 year ago

@talex5 wrote:

But it wraps individual parsers that raise Failure on error, because plumbing result types through all the parsing code is slow

Right, that's what made me think that the exception should be the fast one, as callers can then aggregate them into a single result.

But this can all be fixed later with affecting the interfaces in this PR. I'm good with merging this if you could add some tests, @torinnd

torinnd commented 1 year ago

I've taken a stab at putting a test harness together, but am bumping into the following ocaml-ci error: 2023-01-24 15:01.16: Job failed: Error from solver: Unix.Unix_error(Unix.EMFILE, "pipe", "")

I'm not sure if this is an issue with the PR or the CI tooling

talex5 commented 1 year ago

2023-01-24 15:01.16: Job failed: Error from solver: Unix.Unix_error(Unix.EMFILE, "pipe", "") I'm not sure if this is an issue with the PR or the CI tooling

It's a problem with the CI certainly. The CI team are aware of it.

talex5 commented 1 year ago

The new error is likely a problem with the PR however:

File "lib_test/test_runner.ml", line 727, characters 33-37:
727 |   eval_rfc9110_uris http_uris ~f:eval
                                       ^^^^
Error: This expression has type
         input:string -> (Uri.Absolute_http.t, string) result -> unit
       but an expression was expected of type
         input:string ->
         (Uri.Absolute_http.t, [ `Msg of string ]) result -> unit
       Type string is not compatible with type [ `Msg of string ] 
tmcgilchrist commented 1 year ago

@torinnd the CI issue is resolved, could you try rebasing this PR. Thanks

torinnd commented 1 year ago

Checks cleared! Thanks for getting the opam issue sorted @tmcgilchrist !

torinnd commented 1 year ago

@avsm are you open to merging this? I think we've sorted all of the feedback raised in this PR.

avsm commented 1 year ago

Merged, and released to opam. Thanks for the contribution!