Skip to content

Commit f1626e2

Browse files
committed
Evaluate error message before resetting error state in macros (#1406)
This PR adjusts the ROS error-state reset behavior in the C++/N-API helper macros so the error message can be captured before the global RCL error state is cleared, improving the fidelity of JavaScript exceptions thrown from native bindings. **Changes:** - Move `rcl_reset_error()` to occur *after* `Napi::Error::New(...).ThrowAsJavaScriptException()` in `CHECK_OP_AND_THROW_ERROR_IF_NOT_TRUE`. - Apply the same ordering fix to the `_NO_RETURN` variant. Fix: #1405
1 parent 9fa5ed0 commit f1626e2

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/macros.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@
2222
#define CHECK_OP_AND_THROW_ERROR_IF_NOT_TRUE(op, lhs, rhs, message) \
2323
{ \
2424
if (lhs op rhs) { \
25-
rcl_reset_error(); \
2625
Napi::Error::New(env, message).ThrowAsJavaScriptException(); \
26+
rcl_reset_error(); \
2727
return env.Undefined(); \
2828
} \
2929
}
3030

3131
#define CHECK_OP_AND_THROW_ERROR_IF_NOT_TRUE_NO_RETURN(op, lhs, rhs, message) \
3232
{ \
3333
if (lhs op rhs) { \
34-
rcl_reset_error(); \
3534
Napi::Error::New(env, message).ThrowAsJavaScriptException(); \
35+
rcl_reset_error(); \
3636
} \
3737
}
3838

0 commit comments

Comments
 (0)