[BUG] Incorrect exception type when using Boost futures
karzhenkov opened this issue · 4 comments
The following program reports an exception of unknown type when REDIS_PLUS_PLUS_ASYNC_FUTURE
is set to boost
and there is no running Redis server:
#include <sw/redis++/async_redis++.h>
#include <iostream>
int main() {
sw::redis::AsyncRedis redis("tcp://127.0.0.1:6379");
try {
if (auto value = redis.get("key").get()) {
std::cout << "value: " << *value << std::endl;
}
} catch (const sw::redis::Error& e) {
std::cerr << "[sw::redis::Error] " << e.what() << '\n';
} catch (const std::exception& e) {
std::cerr << "[std::exception] " << e.what() << '\n';
} catch (...) {
std::cerr << "[unknown error]\n";
}
}
The output is as follows:
[unknown error]
Without REDIS_PLUS_PLUS_ASYNC_FUTURE
, the output looks as expected:
[sw::redis::Error] failed to connect to Redis (127.0.0.1:6379): Connection refused
Environment:
- OS: ubuntu
- Compiler: gcc 13.2.0
- hiredis version: v1.2.0
- redis-plus-plus version: master, commit 5eccac2
Additional context
The problem might be related to using std::exception_ptr
where boost::exception_ptr
is needed.
What's your boost version? The minimum version requirement for Boost is 1.55.0.
I'm not sure if this is a duplicated issue with this one.
Regards
Hi, @sewenew. My boost version is 1.74.0, so it should work. In addition, the issue you mentioned is about compile-time error. The problem reported here occurs at runtime.
Thanks for pointing it out! I'll take a look into it.
Regards
After some research, I found the problem lies on boost::promise::set(std::exception_ptr)
.
When something bad happens, e.g. failed to connect to Redis, we call promise::set
to report error. When boost enabled, it's boost::promise
. However, when we call boost::promise::set(std::exception_ptr)
, the exception type info loses.
So far, I do not find any cheaper solution to fix it. If you have any idea, feel free to let me know.
Regards