Skip to content
This repository was archived by the owner on May 31, 2025. It is now read-only.

Replace message assertion with logging in order to have release modes…#2096

Merged
jacobperron merged 1 commit intoros:noetic-develfrom
tahsinkose:fix-msg-assertion-in-release
Dec 10, 2020
Merged

Replace message assertion with logging in order to have release modes…#2096
jacobperron merged 1 commit intoros:noetic-develfrom
tahsinkose:fix-msg-assertion-in-release

Conversation

@tahsinkose
Copy link
Copy Markdown
Contributor

@tahsinkose tahsinkose commented Nov 25, 2020

… to fail in compilation when msg type mismatches occur.

Fixes #2095.

@tahsinkose tahsinkose force-pushed the fix-msg-assertion-in-release branch from 650a66d to 3a800c4 Compare November 25, 2020 12:04
Comment on lines +80 to +83
ROS_DEBUG("Trying to publish message of type [%s/%s] on a "
"publisher with type [%s/%s]",
mt::datatype<M>(*message), mt::md5sum<M>(*message),
impl_->datatype_.c_str(), impl_->md5sum_.c_str());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How about adding if statement to check message type, then call ROS_FATAL and ROS_BREAK? i think this is fatal information since it does not publish the correct message as user application expects.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

With this, it won't even compile in case of such a type mismatch. ROS_DEBUG is just a macro that I'm sure of not being opt-out by the compiler in release mode 🙂 Any similar line could be replaced with it. The important bits are mt::datatype<M>(*message) and mt::md5sum<M>(*message), which fail when type mismatch occurs.

I mean, replacements with ROS_FATAL or ROS_BREAK won't compile either. Ultimately, any mismatches in the published messages will be captured in compile-time.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ROS_DEBUG is just a macro that I'm sure of not being opt-out by the compiler in release mode

i do not think so, it actually depends on build environment.

https://github.com/ros/rosconsole/blob/854b3a1ec426e173383d2cf1d241c5626ec33715/include/ros/console.h#L314-L321

in default, it does not opt-out ROS_DEBUG nor ROS_FATAL. (So that we can see the ROS_INFO with release mode)

ROS_BREAK is the same with ROS_ASSERT_MSG, which i think it would be nice to abort when it is built with debug mode.

The important bits are mt::datatype(*message) and mt::md5sum(*message), which fail when type mismatch occurs.

that is exactly why i was thinking that using if statement to check impl_->md5sum_ == "*" || std::string(mt::md5sum<M>(*message)) == "*" || impl_->md5sum_ == mt::md5sum<M>(*message) then print message. and with debug built it goes abort.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So, do you suggest guarding ROS_DEBUG/ROS_BREAK statement with an if-check, which would be never opt-out?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes. ROS_BREAK will be opt-out with release build as i mentioned previous comment. but as far as I see, this seems to be a fatal problem for user application because message cannot be delivered to the other side. of course this is just my idea, so I'd like to hear from others.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If we guard with if-check, such delivery is irrelevant in here as it will never compile in release mode, too. I'm trying to make sure that the mismatches in delivery are noticed in compile-time.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

okay, i see what you mean. type mismatch will be checked during compile time, then just prints the debug information if user configures loglevel into debug. that makes sense. thanks for iterating 👍

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added. PTAL @fujitatomoya

"Trying to publish message of type [%s/%s] on a publisher with type [%s/%s]",
mt::datatype<M>(message), mt::md5sum<M>(message),
impl_->datatype_.c_str(), impl_->md5sum_.c_str());
ROS_DEBUG("Trying to publish message of type [%s/%s] on a "
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same here.

@tahsinkose tahsinkose force-pushed the fix-msg-assertion-in-release branch 2 times, most recently from 4535f88 to bc44432 Compare December 1, 2020 14:35
… to fail in compilation when msg type mismatches occur.
@tahsinkose tahsinkose force-pushed the fix-msg-assertion-in-release branch from bc44432 to d99022e Compare December 1, 2020 14:36
@tahsinkose
Copy link
Copy Markdown
Contributor Author

@sloretz You seem to be the latest maintainer. Could you please have a look?

@jacobperron jacobperron self-assigned this Dec 10, 2020
Copy link
Copy Markdown
Contributor

@jacobperron jacobperron left a comment

Choose a reason for hiding this comment

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

The change LGTM. Cheers!

@jacobperron jacobperron merged commit d2216c0 into ros:noetic-devel Dec 10, 2020
jacobperron pushed a commit that referenced this pull request Apr 6, 2021
… to fail in compilation when msg type mismatches occur (#2096)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ROS_ASSERT_MSG check on md5_sum of publish is ignored in release modes.

3 participants