Skip to content
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

Capture cdr exceptions #505

Merged
merged 4 commits into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
30 changes: 18 additions & 12 deletions rmw_fastrtps_cpp/src/type_support_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <fastcdr/exceptions/Exception.h>

#include <string>

#include "rmw/error_handling.h"
Expand Down Expand Up @@ -88,20 +90,24 @@ bool TypeSupport::deserializeROSmessage(
assert(ros_message);
assert(impl);

// Deserialize encapsulation.
deser.read_encapsulation();

// If type is not empty, deserialize message
if (has_data_) {
auto callbacks = static_cast<const message_type_support_callbacks_t *>(impl);
return callbacks->cdr_deserialize(deser, ros_message);
try {
// Deserialize encapsulation.
deser.read_encapsulation();

// If type is not empty, deserialize message
if (has_data_) {
auto callbacks = static_cast<const message_type_support_callbacks_t *>(impl);
return callbacks->cdr_deserialize(deser, ros_message);
}

// Otherwise, consume dummy byte
uint8_t dump = 0;
deser >> dump;
(void)dump;
} catch (const eprosima::fastcdr::exception::Exception &) {
return false;
Copy link
Collaborator

Choose a reason for hiding this comment

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

what about using RCUTILS_LOG_ERROR_NAMED to notify the user what happened?

Copy link
Contributor

Choose a reason for hiding this comment

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

If I may, I'm slight inclined towards RMW_SET_ERROR_MSG instead (see here).

}

// Otherwise, consume dummy byte
uint8_t dump = 0;
deser >> dump;
(void)dump;

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

#include <fastcdr/FastBuffer.h>
#include <fastcdr/Cdr.h>
#include <fastcdr/exceptions/Exception.h>

#include <cassert>
#include <string>
#include <vector>
Expand Down Expand Up @@ -771,7 +773,9 @@ bool TypeSupport<MembersType>::deserializeROSmessage(
{
auto sub_members = static_cast<const MembersType *>(member->members_->data);
if (!member->is_array_) {
deserializeROSmessage(deser, sub_members, field);
if (!deserializeROSmessage(deser, sub_members, field)) {
return false;
}
} else {
size_t array_size = 0;

Expand All @@ -794,7 +798,9 @@ bool TypeSupport<MembersType>::deserializeROSmessage(
return false;
}
for (size_t index = 0; index < array_size; ++index) {
deserializeROSmessage(deser, sub_members, member->get_function(field, index));
if (!deserializeROSmessage(deser, sub_members, member->get_function(field, index))) {
return false;
}
}
}
}
Expand Down Expand Up @@ -936,16 +942,20 @@ bool TypeSupport<MembersType>::deserializeROSmessage(
assert(ros_message);
assert(members_);

// Deserialize encapsulation.
deser.read_encapsulation();
try {
// Deserialize encapsulation.
deser.read_encapsulation();

(void)impl;
if (members_->member_count_ != 0) {
return TypeSupport::deserializeROSmessage(deser, members_, ros_message);
}

(void)impl;
if (members_->member_count_ != 0) {
TypeSupport::deserializeROSmessage(deser, members_, ros_message);
} else {
uint8_t dump = 0;
deser >> dump;
(void)dump;
} catch (const eprosima::fastcdr::exception::Exception &) {
return false;
}

return true;
Expand Down
28 changes: 14 additions & 14 deletions rmw_fastrtps_shared_cpp/src/rmw_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,22 @@ __rmw_take_request(
if (request.buffer_ != nullptr) {
eprosima::fastcdr::Cdr deser(*request.buffer_, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
eprosima::fastcdr::Cdr::DDS_CDR);
info->request_type_support_->deserializeROSmessage(
deser, ros_request, info->request_type_support_impl_);

// Get header
rmw_fastrtps_shared_cpp::copy_from_fastrtps_guid_to_byte_array(
request.sample_identity_.writer_guid(),
request_header->request_id.writer_guid);
request_header->request_id.sequence_number =
((int64_t)request.sample_identity_.sequence_number().high) <<
32 | request.sample_identity_.sequence_number().low;
request_header->source_timestamp = request.sample_info_.sourceTimestamp.to_ns();
request_header->received_timestamp = request.sample_info_.receptionTimestamp.to_ns();
if (info->request_type_support_->deserializeROSmessage(
deser, ros_request, info->request_type_support_impl_))
{
// Get header
rmw_fastrtps_shared_cpp::copy_from_fastrtps_guid_to_byte_array(
request.sample_identity_.writer_guid(),
request_header->request_id.writer_guid);
request_header->request_id.sequence_number =
((int64_t)request.sample_identity_.sequence_number().high) <<
32 | request.sample_identity_.sequence_number().low;
request_header->source_timestamp = request.sample_info_.sourceTimestamp.to_ns();
request_header->received_timestamp = request.sample_info_.receptionTimestamp.to_ns();
*taken = true;
}

delete request.buffer_;

*taken = true;
}

return RMW_RET_OK;
Expand Down
21 changes: 11 additions & 10 deletions rmw_fastrtps_shared_cpp/src/rmw_response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,17 @@ __rmw_take_response(
*response.buffer_,
eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
eprosima::fastcdr::Cdr::DDS_CDR);
info->response_type_support_->deserializeROSmessage(
deser, ros_response, info->response_type_support_impl_);

request_header->source_timestamp = response.sample_info_.sourceTimestamp.to_ns();
request_header->received_timestamp = response.sample_info_.receptionTimestamp.to_ns();
request_header->request_id.sequence_number =
((int64_t)response.sample_identity_.sequence_number().high) <<
32 | response.sample_identity_.sequence_number().low;

*taken = true;
if (info->response_type_support_->deserializeROSmessage(
deser, ros_response, info->response_type_support_impl_))
{
request_header->source_timestamp = response.sample_info_.sourceTimestamp.to_ns();
request_header->received_timestamp = response.sample_info_.receptionTimestamp.to_ns();
request_header->request_id.sequence_number =
((int64_t)response.sample_identity_.sequence_number().high) <<
32 | response.sample_identity_.sequence_number().low;

*taken = true;
}
}

return RMW_RET_OK;
Expand Down