Hi,
I am trying to use https://github.com/mirage/ocaml-github/ and it works fine for the happy path, but I am having some trouble catching exceptions and assume that I misunderstand something about ocaml-github
s monadic interface?
Both compile, both work fine when given a real commits sha, but both are seemingly failing in catching the exception for invalid commit shas; I’d except an exception to be printed, preceeded by "ERROR ", but the output I get is just
Fatal error: exception GitHub API error: 422 Unprocessable Entity (WebDAV) (RFC 4918) -- No commit found for SHA: not-a-real-commit
- without my prefix.
I tried using Github.Monad.catch
as in
let t =
let open Github.Monad in
let token = Github.Token.of_string "my-token"
and user = "ocaml"
and repo = "opam"
in
run Github_t.(
catch
(fun () ->
let sha = "not-a-real-commit" in
Github.Repo.get_commit ~token ~user ~repo ~sha ()
>>~ fun commit ->
return (Printf.eprintf "commit url: %s\n" commit.commit_url))
(function
| e -> return (Printf.eprintf "ERROR %s\n" (Printexc.to_string e)))
)
let () =
Lwt_main.run t
As well as a conventional try-catch-clause:
let t =
let open Github.Monad in
let token = Github.Token.of_string "my-token"
and user = "ocaml"
and repo = "opam"
in
run Github_t.(
try
let sha = "not-a-real-commit" in
Github.Repo.get_commit ~token ~user ~repo ~sha ()
>>~ fun commit ->
return (Printf.eprintf "commit url: %s\n" commit.commit_url)
with
| e -> return (Printf.eprintf "ERROR %s\n" (Printexc.to_string e))
)
let () =
Lwt_main.run t
Thanks for reading, looking forward to any pointers