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

Check existence of a file before passing it to the mcap reader #1594

Merged
merged 2 commits into from
Apr 10, 2024

Conversation

cwecht
Copy link
Contributor

@cwecht cwecht commented Mar 21, 2024

…mcap::FileStreamReader in order to avoid this assertion: failing https://github.com/foxglove/mcap/blob/9d73125e50121c1eeb2ceb9d13db51ff923b0420/cpp/mcap/include/mcap/reader.inl#L90

This is an issue if you happen to run rosbag build in debug mode (in which assertions are enabled). As it is the behavior of debug and release mode is inconsistent as in debug mode the assertion is raised and in release mode an exception is raised.

…mcap::FileStreamReader in order to avoid assertion failing

Signed-off-by: Christopher Wecht <cwecht@mailbox.org>
@cwecht cwecht requested a review from a team as a code owner March 21, 2024 10:27
@cwecht cwecht requested review from gbiggs and jhdcs and removed request for a team March 21, 2024 10:27
@@ -334,6 +335,9 @@ void MCAPStorage::open_impl(const std::string & uri, const std::string & preset_
case rosbag2_storage::storage_interfaces::IOFlag::READ_ONLY: {
relative_path_ = uri;
input_ = std::make_unique<std::ifstream>(relative_path_, std::ios::binary);
if (!input_->is_open()) {
throw std::runtime_error(std::strerror(errno));
Copy link
Contributor

Choose a reason for hiding this comment

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

if input_ failed to open the file during construction, the errno is set accordingly? i was expecting we need to check the failbit instead, but it would be better that we can just use errno!

How about adding more information for runtime error exception?

Suggested change
throw std::runtime_error(std::strerror(errno));
throw std::runtime_error("Failed to open storage " + relative_path_ + std::strerror(errno));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. std::ifstream and errno is a bit complicated: cppreference (hence the C++ standard) don't mention errno at all. However, std::ifstream is usually implemented in terms of fopen/open which in turn is specified to set errno. I think, it is reasonable to realy on this behavior. An alternative could be to set the execption mask of input_ . IMO this has the disadvantage that we would need to disable it after that probably. Otherwise there might occour other exceptions in FileStreamReader, which might not be expected or not dealt with properly.
  2. Regarding the exception message: this exception will be catched here: https://github.com/ros2/rosbag2/blob/rolling/rosbag2_storage/src/rosbag2_storage/impl/storage_factory_impl.hpp#L135 Here, the path is logged already, so there is no need to duplicate this infromation in the exception message.

Copy link
Contributor

Choose a reason for hiding this comment

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

thanks for the explanation! lgtm!

Copy link
Contributor

@MichaelOrlov MichaelOrlov left a comment

Choose a reason for hiding this comment

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

LGTM

@MichaelOrlov MichaelOrlov changed the title rosbag2_storage_mcap: check existence of a file before passing it to … Check existence of a file before passing it to the mcap reader Mar 29, 2024
@MichaelOrlov
Copy link
Contributor

Gist: https://gist.githubusercontent.com/MichaelOrlov/6dee8d20cb96a4d63b417bf6df46932e/raw/624b11e64730f3df462ee2425c8fcd8c6ca7fa78/ros2.repos
BUILD args: --packages-above-and-dependencies rosbag2_storage_mcap rosbag2_tests
TEST args: --packages-above rosbag2_storage_mcap rosbag2_tests
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/13570

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

@MichaelOrlov
Copy link
Contributor

@cwecht There is one new warning on Windows CI build

'strerror': This function or variable may be unsafe. Consider using strerror_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

Could you please address it by using strerror_s instead of the strerror?

Signed-off-by: Christopher Wecht <cwecht@mailbox.org>
@cwecht
Copy link
Contributor Author

cwecht commented Apr 2, 2024

@cwecht There is one new warning on Windows CI build

'strerror': This function or variable may be unsafe. Consider using strerror_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

Could you please address it by using strerror_s instead of the strerror?

Turns out there is already rcutils_strerror so I went with that.

@fujitatomoya
Copy link
Contributor

@cwecht change looks good, CI just starts. 🤞

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

@cwecht
Copy link
Contributor Author

cwecht commented Apr 5, 2024

https://build.ros2.org/job/Rpr__rosbag2__ubuntu_noble_amd64/62/console failing seems to be caused by some kind of hicup/issue on the toolchains/buildservers side, right? In case we need that build to successes, I'd suggest to rerun it.

@cwecht
Copy link
Contributor Author

cwecht commented Apr 10, 2024

@fujitatomoya @MichaelOrlov how do we proceed?

@MichaelOrlov
Copy link
Contributor

@cwecht The buildfarm CI is green we are good to go. Never mind.

@MichaelOrlov MichaelOrlov merged commit 29a8415 into ros2:rolling Apr 10, 2024
13 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants