Skip to content

Commit 39f0a64

Browse files
committed
fix(opcua): write_data() use 3-arg write_value with data_type_hint + error mapping
Bug fix from review: - write_data() was calling 2-arg write_value(node_id, value) (bool return) instead of 3-arg write_value(node_id, value, data_type_hint) (tl::expected return). This meant writes through standard SOVD PUT /data/{name} missed the type hint optimization AND collapsed all errors to generic 502. - Now matches handle_plc_operations() and execute_operation() which correctly pass entry->data_type and map WriteError codes to appropriate HTTP status. Also: remove redundant `using namespace ros2_medkit_gateway;` inside the already-open `namespace ros2_medkit_gateway { }` block.
1 parent 159efdd commit 39f0a64

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

src/ros2_medkit_plugins/ros2_medkit_opcua/src/opcua_plugin.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929

3030
namespace ros2_medkit_gateway {
3131

32-
using namespace ros2_medkit_gateway;
33-
3432
namespace {
3533
bool is_valid_path_segment(const std::string & s) {
3634
if (s.empty() || s.size() > 256) {
@@ -747,9 +745,18 @@ tl::expected<nlohmann::json, DataProviderErrorInfo> OpcuaPlugin::write_data(cons
747745
}
748746
}
749747

750-
if (!client_->write_value(entry->node_id, write_val)) {
751-
return tl::make_unexpected(DataProviderErrorInfo{DataProviderError::TransportError,
752-
"Failed to write value to PLC node: " + entry->node_id_str, 502});
748+
auto write_result = client_->write_value(entry->node_id, write_val, entry->data_type);
749+
if (!write_result) {
750+
auto wcode = write_result.error().code;
751+
if (wcode == OpcuaClient::WriteError::TypeMismatch) {
752+
return tl::make_unexpected(
753+
DataProviderErrorInfo{DataProviderError::InvalidValue, write_result.error().message, 400});
754+
}
755+
if (wcode == OpcuaClient::WriteError::AccessDenied) {
756+
return tl::make_unexpected(DataProviderErrorInfo{DataProviderError::ReadOnly, write_result.error().message, 403});
757+
}
758+
return tl::make_unexpected(
759+
DataProviderErrorInfo{DataProviderError::TransportError, write_result.error().message, 502});
753760
}
754761

755762
nlohmann::json result;

0 commit comments

Comments
 (0)