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

Switch from http-lwt-client and lwt to httpcats and miou #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kit-ty-kate
Copy link
Owner

Experimental

cc @dinosaure

Copy link
Owner Author

@kit-ty-kate kit-ty-kate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Questions and remarks for @dinosaure

| `Malformed_json of string
| `Msg of string
| Httpcats.error
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do users of httpcats really need a list of errors that detailed?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's pretty good and it fits in quite well with your code 👍. A transformation could be reword_error (msgf '%a' Httpcats.pp_error) to produce only a value of type [> Msg of string ]. But specifying whether the error comes from h1 or h2 or the underlying protocol (tcp or tls) or the occurrence of an unknown exception (often raised by the user (him/her)self) can be useful in more precise cases.

| Ok (resp, body) -> Error (`Api_error (resp, body))
| Error e -> Error e
| Error e -> Error (e : Httpcats.error :> [> fetch_errors])
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this should be improved in httpcats. Httpcats.request should return (_, [> error]) result instead of the non polymorphic version of that currently.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are absolutely right!

@@ -350,15 +358,19 @@ module Config = struct
Json.pp fmt json
end

external reraise : exn -> 'a = "%reraise"
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be nice to have in Miou (or in the stdlib but since the stdlib doesn't have it currently it would be nice to have anyway for backward compatibility)

Comment on lines +370 to +374
let fd = Unix.openfile (Fpath.to_string output_file) Unix.[O_WRONLY; O_TRUNC; O_CREAT] 0o666 in
let fd = try Miou_unix.of_file_descr fd with e -> Unix.close fd; reraise e in
Fun.protect ~finally:(fun () -> Miou_unix.close fd) begin fun () ->
Miou_unix.write fd x;
end;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like there is a simpler way to do that. Could Miou_unix provide an openfile function or would it be more something for a higher level library? If it's the latter, is that already planned? If not i'm happy to start one

Comment on lines +29 to +31
~uri:url
(* TODO: This won't work once we handle things that aren't just short and simple JSON *)
~f:(fun _ _ acc body -> match acc, body with
Copy link
Owner Author

@kit-ty-kate kit-ty-kate Sep 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like the new labels (uri and f) are unnecessary too

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The f label is, indeed, not as important as all that, but the uri label is important because it indicates that the string passed is actually interpreted as an uri. The string type can easily be a catch-all type (just look at the OCaml codebase...) and being able to specify that the string expected by request is the uri is I think a good approach.

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

Successfully merging this pull request may close these issues.

2 participants