#14188 GrpcInterface: Propagate parameter validation errors in command service

Make RiaGrpcCommandService::assignPdmObjectValues return std::expected<void, QString> so the result of copyPdmObjectFromRipsToCaf is no longer discarded. Validation failures are now propagated up and returned to the client as a gRPC INVALID_ARGUMENT status instead of being silently ignored. This also resolves the C4834 [[nodiscard]] build warning.
This commit is contained in:
Magne Sjaastad
2026-06-10 12:34:59 +02:00
parent ed96d155fc
commit 76d0ff3d3c
2 changed files with 19 additions and 8 deletions
+18 -7
View File
@@ -84,7 +84,15 @@ grpc::Status RiaGrpcCommandService::Execute( grpc::ServerContext* context, const
}
else
{
assignPdmObjectValues( commandHandle, *request, grpcOneOfMessage );
auto result = assignPdmObjectValues( commandHandle, *request, grpcOneOfMessage );
if ( !result )
{
telemetryAttributes["command.status"] = "error";
telemetryAttributes["command.error"] = result.error().toStdString();
RiaOpenTelemetryManager::instance().reportEventAsync( "grpc.command_execute", telemetryAttributes );
return grpc::Status( grpc::INVALID_ARGUMENT, result.error().toStdString() );
}
telemetryAttributes["command.type"] = "standard";
}
@@ -260,9 +268,10 @@ void RiaGrpcCommandService::assignPdmFieldValue( caf::PdmValueField* pdmValue
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaGrpcCommandService::assignPdmObjectValues( caf::PdmObjectHandle* pdmObjectHandle,
const google::protobuf::Message& params,
const google::protobuf::FieldDescriptor* paramDescriptor )
std::expected<void, QString>
RiaGrpcCommandService::assignPdmObjectValues( caf::PdmObjectHandle* pdmObjectHandle,
const google::protobuf::Message& params,
const google::protobuf::FieldDescriptor* paramDescriptor )
{
FieldDescriptor::Type fieldDataType = paramDescriptor->type();
const Reflection* reflection = params.GetReflection();
@@ -274,8 +283,7 @@ void RiaGrpcCommandService::assignPdmObjectValues( caf::PdmObjectHandle*
const rips::PdmObject* ripsPdmObject = dynamic_cast<const rips::PdmObject*>( &subMessage );
if ( ripsPdmObject )
{
copyPdmObjectFromRipsToCaf( ripsPdmObject, pdmObjectHandle );
return;
return copyPdmObjectFromRipsToCaf( ripsPdmObject, pdmObjectHandle );
}
auto messageDescriptor = paramDescriptor->message_type();
@@ -306,7 +314,8 @@ void RiaGrpcCommandService::assignPdmObjectValues( caf::PdmObjectHandle*
CAF_ASSERT( childObject );
if ( childObject )
{
assignPdmObjectValues( childObject, subMessage, parameter );
auto result = assignPdmObjectValues( childObject, subMessage, parameter );
if ( !result ) return result;
}
}
else if ( pdmValueFieldHandle )
@@ -315,6 +324,8 @@ void RiaGrpcCommandService::assignPdmObjectValues( caf::PdmObjectHandle*
}
}
}
return {};
}
//--------------------------------------------------------------------------------------------------
+1 -1
View File
@@ -60,7 +60,7 @@ private:
void assignPdmFieldValue( caf::PdmValueField* pdmValueField,
const google::protobuf::Message& params,
const google::protobuf::FieldDescriptor* paramDescriptor );
void assignPdmObjectValues( caf::PdmObjectHandle* pdmObject,
std::expected<void, QString> assignPdmObjectValues( caf::PdmObjectHandle* pdmObject,
const google::protobuf::Message& params,
const google::protobuf::FieldDescriptor* paramDescriptor );