Skip to content

Commit e2bfcd7

Browse files
committed
feat: client.get_response fills in a per-call error param fixing lastError mismatch
feat: RpcError .copy
1 parent a593af1 commit e2bfcd7

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/client.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ class RPCClient {
4141
}
4242

4343
// blocking call
44-
while (!get_response(msg_id_wait, result)){
44+
RpcError tmp_error;
45+
while (!get_response(msg_id_wait, result, tmp_error)) {
4546
//delay(1);
4647
}
4748

@@ -60,17 +61,14 @@ class RPCClient {
6061
}
6162

6263
template<typename RType>
63-
bool get_response(const uint32_t wait_id, RType& result) {
64-
RpcError tmp_error;
64+
bool get_response(const uint32_t wait_id, RType& result, RpcError& error) {
6565
decoder->decode();
6666

67-
if (decoder->get_response(wait_id, result, tmp_error)) {
68-
lastError.code = tmp_error.code;
69-
lastError.traceback = tmp_error.traceback;
67+
if (decoder->get_response(wait_id, result, error)) {
68+
lastError.copy(error);
7069
return true;
71-
} else if (tmp_error.code == PARSING_ERR) { // catches the parsing error
72-
lastError.code = tmp_error.code;
73-
lastError.traceback = tmp_error.traceback;
70+
} else if (error.code == PARSING_ERR) { // catches the parsing error
71+
lastError.copy(error);
7472
}
7573
return false;
7674
}

src/error.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ struct RpcError {
3535
RpcError(const int c, MsgPack::str_t tb)
3636
: code(c), traceback(std::move(tb)) {}
3737

38+
void copy(const RpcError& err) {
39+
code = err.code;
40+
traceback = err.traceback;
41+
}
42+
3843
MSGPACK_DEFINE(code, traceback); // -> [code, traceback]
3944
};
4045

0 commit comments

Comments
 (0)