Skip to content

Conversation

@evgenykor
Copy link
Contributor

No description provided.

@guycipher
Copy link
Member

static void inline err_handler(tidesdb_err_t *err)
{
    if (err)
    {
        std::string error_message = err->message;
        const int error_code = err->code;
        tidesdb_err_free(err);
        throw std::runtime_error("Error " + std::to_string(error_code) + ": " + error_message);
    }
}

One question @evgenykor aren't you freeing the error? I'm not sure if we are copying the message, usually you copy the char array, also the const is redundant in such a local method no? Do let me know thoughts. I like the idea. I just think you're freeing the message by accident, I may be wrong though.

@evgenykor
Copy link
Contributor Author

evgenykor commented Jan 14, 2025

No, std::string error_message contructor will do deep copy of message so it is fine. We also have a negative test in CI

    catch (const std::runtime_error& e)
    {
        EXPECT_STREQ(e.what(), "Error 22: Key not found.\n");
    }

this would have a an issue otherwise accessing e.what()

Of course I am not freeing it by accident - we do need to free error since you allocate memory for it (if the error occurs)

And lastly code was like this even before my PR :) this just deduplication work

@evgenykor
Copy link
Contributor Author

evgenykor commented Jan 14, 2025

argument about int error_code is valid but I played too much with these Rust / Zig toys to have bias / schizofrenia of making all the world const

@guycipher guycipher merged commit 2c722b4 into tidesdb:master Jan 14, 2025
1 check passed
@guycipher
Copy link
Member

I agree with the test. I had a feeling about the deep copy I just wanted to be sure. Too much C on my end.

Great work as always! @evgenykor

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