Skip to content

Commit

Permalink
Add empty function checks in CalleeHandle
Browse files Browse the repository at this point in the history
The CalleeHandle class is the "owner" of the callback function objects
associated with a callback connection. As such, it will check the
validity of those function objects and throw the EmptyFunctionObject
exception if either the callback or cleanup function is empty / invalid.
  • Loading branch information
gregmedd committed Aug 17, 2024
1 parent 2f8285e commit 45f3dba
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions include/up-cpp/utils/CallbackConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,21 @@ struct [[nodiscard]] CalleeHandle {
"Attempted to create a connected CalleeHandle with bad "
"connection pointer");
}

if (!callback_) {
throw BadConnection(
"Attempted to create a connected CalleeHandle with bad "
"callback pointer");
}

const auto& callback_obj = *callback_;
if (!callback_obj) {
throw EmptyFunctionObject("Callback function is empty");
}

if (cleanup_ && !cleanup_.value()) {
throw EmptyFunctionObject("Cleanup function is empty");
}
}

/// @brief CalleeHandles can be move constructed
Expand Down

0 comments on commit 45f3dba

Please sign in to comment.