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

Improve Error Reporting and Reduce Log Redundancy #327

Merged
Changes from all 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
28 changes: 27 additions & 1 deletion ros1_foxglove_bridge/src/ros1_foxglove_bridge_nodelet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ constexpr uint32_t SUBSCRIPTION_QUEUE_LENGTH = 10;
constexpr double MIN_UPDATE_PERIOD_MS = 100.0;
constexpr uint32_t PUBLICATION_QUEUE_LENGTH = 10;
constexpr int DEFAULT_SERVICE_TYPE_RETRIEVAL_TIMEOUT_MS = 250;
constexpr int MAX_INVALID_PARAMS_TRACKED = 1000;

using ConnectionHandle = websocketpp::connection_hdl;
using TopicAndDatatype = std::pair<std::string, std::string>;
Expand Down Expand Up @@ -656,6 +657,7 @@ class FoxgloveBridge : public nodelet::Nodelet {

bool success = true;
std::vector<foxglove::Parameter> params;
std::vector<std::string> invalidParams;
for (const auto& paramName : parameterNames) {
if (!isWhitelisted(paramName, _paramWhitelistPatterns)) {
if (allParametersRequested) {
Expand All @@ -665,27 +667,50 @@ class FoxgloveBridge : public nodelet::Nodelet {
success = false;
}
}
if (_invalidParams.find(paramName) != _invalidParams.end()) {
continue;
}

try {
XmlRpc::XmlRpcValue value;
getMTNodeHandle().getParam(paramName, value);
params.push_back(fromRosParam(paramName, value));
} catch (const std::exception& ex) {
ROS_ERROR("Invalid parameter '%s': %s", paramName.c_str(), ex.what());
invalidParams.push_back(paramName);
success = false;
} catch (const XmlRpc::XmlRpcException& ex) {
ROS_ERROR("Invalid parameter '%s': %s", paramName.c_str(), ex.getMessage().c_str());
invalidParams.push_back(paramName);
success = false;
} catch (...) {
ROS_ERROR("Invalid parameter '%s'", paramName.c_str());
invalidParams.push_back(paramName);
success = false;
}
}

_server->publishParameterValues(hdl, params, requestId);

if (!success) {
throw std::runtime_error("Failed to retrieve one or multiple parameters");
for (std::string& param : invalidParams) {
if (_invalidParams.size() < MAX_INVALID_PARAMS_TRACKED) {
_invalidParams.insert(param);
}
}

if (!invalidParams.empty()) {
std::string errorMsg = "Failed to retrieve the following parameters: ";
for (size_t i = 0; i < invalidParams.size(); i++) {
errorMsg += invalidParams[i];
if (i < invalidParams.size() - 1) {
errorMsg += ", ";
}
}
throw std::runtime_error(errorMsg);
} else {
throw std::runtime_error("Failed to retrieve one or multiple parameters");
}
}
}

Expand Down Expand Up @@ -922,6 +947,7 @@ class FoxgloveBridge : public nodelet::Nodelet {
int _serviceRetrievalTimeoutMs = DEFAULT_SERVICE_TYPE_RETRIEVAL_TIMEOUT_MS;
std::atomic<bool> _subscribeGraphUpdates = false;
std::unique_ptr<foxglove::CallbackQueue> _fetchAssetQueue;
std::unordered_set<std::string> _invalidParams;
};

} // namespace foxglove_bridge
Expand Down
Loading