ygrek / ocurl

OCaml bindings to libcurl
https://ygrek.org/p/ocurl
MIT License
59 stars 32 forks source link

Expose error code if caml_curl_multi_add_handle fails #41

Closed dwwoelfel closed 3 years ago

dwwoelfel commented 3 years ago

I'm seeing occasional errors when I add an easy handle to the multi interface (with Curl.Multi.add).

The stack trace doesn't give too much information, just Failure caml_curl_multi_add_handle Raised by primitive operation at Curl in file "curl.ml" (inlined), line 1369, which is raised at this line caml_curl_multi_add_handle.

There might be some useful debug information for us in the error code returned by curl_multi_add_handle, but right now that error code is not exposed.

Would you be open to exposing that error somehow?

A couple of ideas for how to expose it:

  1. Add a get_last_error function to Curl.Multi that returns an optional error code if there was an error
  2. Implement a custom OCaml exception function as in https://ocaml.org/manual/intfc.html#ss:c-register-exn

I'd be happy to try to implement it if you can give me some direction on how you'd like to see it implemented.

ygrek commented 3 years ago

Try git master. General improvement could be turning Multi.Error of string (* CURLMcode string *) into Multi.Error of string (* function name *) * CURLMcode

dwwoelfel commented 3 years ago

Thanks! Master is working for me.

ygrek commented 3 years ago

added Multi.CError and covered all functions in 2e3313712f167738df228b3e276bc24df27d9324