Skip to content

Commit

Permalink
ros2GH-7 Further improve exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin-Idel-SI committed Oct 30, 2018
1 parent e6dacb3 commit 4e4b46a
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions rosbag2_transport/src/rosbag2_transport/rosbag2_transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,37 +99,39 @@ void Rosbag2Transport::play(

void Rosbag2Transport::print_bag_info(const std::string & uri)
{
rosbag2::BagMetadata metadata;
try {
auto metadata = info_->read_metadata(uri);
auto start_time = metadata.starting_time.time_since_epoch();
auto end_time = start_time + metadata.duration;
auto formatter = std::make_unique<Formatter>();
std::stringstream info_stream;
int indentation_spaces = 22; // The longest info field (Serialization format:) plus one space.

info_stream << std::endl;
info_stream << "Files: ";
formatter->format_file_paths(metadata.relative_file_paths, info_stream, indentation_spaces);
info_stream << "Bag size: " << formatter->format_file_size(
metadata.bag_size) << std::endl;
info_stream << "Storage id: " << metadata.storage_identifier << std::endl;
info_stream << "Serialization format: " << metadata.serialization_format << std::endl;
info_stream << "Duration: " << formatter->format_duration(
metadata.duration)["time_in_sec"] << "s" << std::endl;
info_stream << "Start: " << formatter->format_time_point(start_time) <<
std::endl;
info_stream << "End " << formatter->format_time_point(end_time) << std::endl;
info_stream << "Messages: " << metadata.message_count << std::endl;
info_stream << "Topics with Type: ";
formatter->format_topics_with_type(
metadata.topics_with_message_count, info_stream, indentation_spaces);

std::cout << info_stream.str() << std::endl;
metadata = info_->read_metadata(uri);
} catch (std::runtime_error & e) {
(void) e;
ROSBAG2_TRANSPORT_LOG_ERROR_STREAM("Could not read metadata for " << uri << ". Please specify "
"the path to the folder containing an existing 'metadata.yaml' file");
return;
}
auto start_time = metadata.starting_time.time_since_epoch();
auto end_time = start_time + metadata.duration;
auto formatter = std::make_unique<Formatter>();
std::stringstream info_stream;
int indentation_spaces = 22; // The longest info field (Serialization format:) plus one space.

info_stream << std::endl;
info_stream << "Files: ";
formatter->format_file_paths(metadata.relative_file_paths, info_stream, indentation_spaces);
info_stream << "Bag size: " << formatter->format_file_size(
metadata.bag_size) << std::endl;
info_stream << "Storage id: " << metadata.storage_identifier << std::endl;
info_stream << "Serialization format: " << metadata.serialization_format << std::endl;
info_stream << "Duration: " << formatter->format_duration(
metadata.duration)["time_in_sec"] << "s" << std::endl;
info_stream << "Start: " << formatter->format_time_point(start_time) <<
std::endl;
info_stream << "End " << formatter->format_time_point(end_time) << std::endl;
info_stream << "Messages: " << metadata.message_count << std::endl;
info_stream << "Topics with Type: ";
formatter->format_topics_with_type(
metadata.topics_with_message_count, info_stream, indentation_spaces);

std::cout << info_stream.str() << std::endl;
}

} // namespace rosbag2_transport

0 comments on commit 4e4b46a

Please sign in to comment.