etesync / libetebase

The C client-side library
BSD 3-Clause "New" or "Revised" License
29 stars 9 forks source link

`etebase_client_new` throw `ETEBASE_ERROR_CODE_MSG_PACK` #3

Closed knacky34 closed 3 years ago

knacky34 commented 3 years ago

I trying to implement Etebase on my application but I'm getting stuck on etebase_client_new function which throws ETEBASE_ERROR_CODE_MSG_PACK. I would know in which case this exception is thrown ? Also, I would know what is the purpose of the first argument const char *client_name of the function ?

Here is my code :

EtebaseErrorCode EteSync::createClient(std::string &customServerUrl, EtebaseClient **client) {
    const char *serverUrl = serverUrl.empty() ? etebase_get_default_server_url() : customServerUrl.c_str();

    *client = etebase_client_new("client", serverUrl);
    EtebaseErrorCode err = etebase_error_get_code();
    if (err != ETEBASE_ERROR_CODE_NO_ERROR) {
        return err;
    }

    ...

    return ETEBASE_ERROR_CODE_NO_ERROR;
}

Thank you

tasn commented 3 years ago

client_name: should be for error messages, but also user agent for the http request. msgpack error: means that serializing (or more likely deserializing) the request failed. Most likely because it's not actually an etebase server you are connecting to.

Also, the code is wrong. You should only check the error code if client is NULL. If the previous function did not return null, the value of err is undefined.

knacky34 commented 3 years ago

Thank you for your answer ! I'm currently working on an API reference, only for C/C++ for now. I will modify the doc according to your comment.

So, it would be nice if we could work together to develop this API reference, because for example it's almost impossible for me to know what exceptions could throw a function because I have to guess it. I've opened a pull request etebase-docs#27

tasn commented 3 years ago

Exceptions: that's a bit opaque at the moment (not documented).

Anyhow, I'm closing this ticket as the issue is solved. Let's talk in the PR.