|
14 | 14 |
|
15 | 15 | #include "rosbag2_cpp/message_definitions/local_message_definition_source.hpp"
|
16 | 16 |
|
17 |
| -#include <rcutils/logging_macros.h> |
18 |
| - |
19 | 17 | #include <fstream>
|
20 | 18 | #include <functional>
|
21 | 19 | #include <optional>
|
|
27 | 25 |
|
28 | 26 | #include <ament_index_cpp/get_package_share_directory.hpp>
|
29 | 27 |
|
| 28 | +#include "rosbag2_cpp/logging.hpp" |
| 29 | + |
30 | 30 | namespace rosbag2_cpp
|
31 | 31 | {
|
| 32 | + |
| 33 | +/// A type name did not match expectations, so a definition could not be looked for. |
| 34 | +class TypenameNotUnderstoodError : public std::exception |
| 35 | +{ |
| 36 | +private: |
| 37 | + std::string name_; |
| 38 | + |
| 39 | +public: |
| 40 | + explicit TypenameNotUnderstoodError(std::string name) |
| 41 | + : name_(std::move(name)) |
| 42 | + {} |
| 43 | + |
| 44 | + const char * what() const noexcept override |
| 45 | + { |
| 46 | + return name_.c_str(); |
| 47 | + } |
| 48 | +}; |
| 49 | + |
32 | 50 | // Match datatype names (foo_msgs/Bar or foo_msgs/msg/Bar)
|
33 | 51 | static const std::regex PACKAGE_TYPENAME_REGEX{R"(^([a-zA-Z0-9_]+)/(?:msg/)?([a-zA-Z0-9_]+)$)"};
|
34 | 52 |
|
@@ -144,7 +162,7 @@ const LocalMessageDefinitionSource::MessageSpec & LocalMessageDefinitionSource::
|
144 | 162 | std::smatch match;
|
145 | 163 | const auto topic_type = definition_identifier.topic_type();
|
146 | 164 | if (!std::regex_match(topic_type, match, PACKAGE_TYPENAME_REGEX)) {
|
147 |
| - throw std::invalid_argument("Invalid topic_type: " + topic_type); |
| 165 | + throw TypenameNotUnderstoodError(topic_type); |
148 | 166 | }
|
149 | 167 | std::string package = match[1];
|
150 | 168 | std::string share_dir = ament_index_cpp::get_package_share_directory(package);
|
@@ -195,26 +213,30 @@ rosbag2_storage::MessageDefinition LocalMessageDefinitionSource::get_full_text(
|
195 | 213 | try {
|
196 | 214 | result = append_recursive(DefinitionIdentifier(root_topic_type, format), max_recursion_depth);
|
197 | 215 | } catch (const DefinitionNotFoundError & err) {
|
198 |
| - // log that we've fallen back |
199 |
| - RCUTILS_LOG_WARN_NAMED( |
200 |
| - "rosbag2_cpp", "no .msg definition for %s, falling back to IDL", |
201 |
| - err.what()); |
| 216 | + ROSBAG2_CPP_LOG_WARN("No .msg definition for %s, falling back to IDL", err.what()); |
202 | 217 | format = Format::IDL;
|
203 | 218 | DefinitionIdentifier root_definition_identifier(root_topic_type, format);
|
204 | 219 | result = (delimiter(root_definition_identifier) +
|
205 | 220 | append_recursive(root_definition_identifier, max_recursion_depth));
|
| 221 | + } catch (const TypenameNotUnderstoodError & err) { |
| 222 | + ROSBAG2_CPP_LOG_ERROR( |
| 223 | + "Message type name '%s' not understood by type definition search, " |
| 224 | + "definition will be left empty in bag.", err.what()); |
| 225 | + format = Format::UNKNOWN; |
206 | 226 | }
|
207 | 227 | rosbag2_storage::MessageDefinition out;
|
208 | 228 | switch (format) {
|
209 | 229 | case Format::UNKNOWN:
|
210 |
| - throw std::runtime_error{"could not determine format of message definition for type " + |
211 |
| - root_topic_type}; |
| 230 | + out.encoding = "unknown"; |
| 231 | + break; |
212 | 232 | case Format::MSG:
|
213 | 233 | out.encoding = "ros2msg";
|
214 | 234 | break;
|
215 | 235 | case Format::IDL:
|
216 | 236 | out.encoding = "ros2idl";
|
217 | 237 | break;
|
| 238 | + default: |
| 239 | + throw std::runtime_error("switch is not exhaustive"); |
218 | 240 | }
|
219 | 241 | out.encoded_message_definition = result;
|
220 | 242 | out.topic_type = root_topic_type;
|
|
0 commit comments