Skip to content

Improve error handling to distinguishes errors #10

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ run-example: target/tikv-example
RUST_LOG=debug $(cur_makefile_path)/target/tikv-example

target/tikv-example: target/debug/libtikv_client.a example/main.cpp
c++ $(cur_makefile_path)/example/main.cpp -o $(cur_makefile_path)/target/tikv-example -std=c++17 -g -I$(cur_makefile_path)/include -L$(cur_makefile_path)/target/debug -ltikv_client -lpthread -ldl -lssl -lcrypto
c++ $(cur_makefile_path)/example/main.cpp -o $(cur_makefile_path)/target/tikv-example -std=c++17 -g -I$(cur_makefile_path)/include -L$(cur_makefile_path)/target/debug -ltikv_client -lpthread -ldl -L/usr/local/opt/openssl/lib -I/usr/local/opt/openssl/include -lssl -lcrypto
Copy link
Author

Choose a reason for hiding this comment

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

I had to manually link ssl and lcrypto libraries so had to change this but will revert it as soon as other changes are approved.



target/tikv_client_glue.cc: src/lib.rs
Expand Down
23 changes: 23 additions & 0 deletions include/tikv_client_glue.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,29 @@ template <typename T>
Box<T>::Box(uninit) noexcept {}
#endif // CXXBRIDGE1_RUST_BOX

class Exception : public std::exception {
public:
Exception(int errorCode, const std::string &message) : errorCode(erroCode), message(message);
virtual ~Exception() = default;
const char* what() const {
return this->message.c_str();
};

private:
int errorCode;
std::string m_message;
};

template <typename Try>
static void trycatch(Try &&func) noexcept try {
func();
} catch (const std::exception &e) {
start error_message = e.what();
int error_code = 0;
Copy link
Author

Choose a reason for hiding this comment

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

How should we get the error_code via stl: map or using string comparison?

Copy link
Collaborator

Choose a reason for hiding this comment

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

We need to define the error_code on rust binding and pass it to the cpp glue.


throw Exception(error_code, error_message);
}

#ifndef CXXBRIDGE1_RUST_BITCOPY
#define CXXBRIDGE1_RUST_BITCOPY
struct unsafe_bitcopy_t final {
Expand Down