From fdd5b03db1910e9fc03b6a5c79caf7781ad44199 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 9 Jun 2026 14:36:26 +0200 Subject: [PATCH 1/2] #14188 GrpcInterface: Propagate parameter validation errors in command service Make RiaGrpcCommandService::assignPdmObjectValues return std::expected 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. --- GrpcInterface/RiaGrpcCommandService.cpp | 25 ++++++++++++++++++------- GrpcInterface/RiaGrpcCommandService.h | 2 +- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/GrpcInterface/RiaGrpcCommandService.cpp b/GrpcInterface/RiaGrpcCommandService.cpp index 349ba85fcbf..455bb5543f8 100644 --- a/GrpcInterface/RiaGrpcCommandService.cpp +++ b/GrpcInterface/RiaGrpcCommandService.cpp @@ -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 + 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( &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 {}; } //-------------------------------------------------------------------------------------------------- diff --git a/GrpcInterface/RiaGrpcCommandService.h b/GrpcInterface/RiaGrpcCommandService.h index 3b7edcf134a..9e8eec780ad 100644 --- a/GrpcInterface/RiaGrpcCommandService.h +++ b/GrpcInterface/RiaGrpcCommandService.h @@ -60,7 +60,7 @@ class RiaGrpcCommandService : public rips::Commands::AsyncService, public RiaGrp void assignPdmFieldValue( caf::PdmValueField* pdmValueField, const google::protobuf::Message& params, const google::protobuf::FieldDescriptor* paramDescriptor ); - void assignPdmObjectValues( caf::PdmObjectHandle* pdmObject, + std::expected assignPdmObjectValues( caf::PdmObjectHandle* pdmObject, const google::protobuf::Message& params, const google::protobuf::FieldDescriptor* paramDescriptor ); From 0440a08b56f7cdac53d80a73bda41e8a492543bc Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 9 Jun 2026 14:46:06 +0200 Subject: [PATCH 2/2] #14188 GrpcInterface: Handle copyPdmObjectFromRipsToCaf result in CallPdmObjectMethod The return value of copyPdmObjectFromRipsToCaf was discarded when copying method parameters in CallPdmObjectMethod. Check the std::expected result and return a gRPC INVALID_ARGUMENT status (with telemetry and logging) when parameter validation fails, instead of silently proceeding to execute the method. --- GrpcInterface/RiaGrpcPdmObjectService.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/GrpcInterface/RiaGrpcPdmObjectService.cpp b/GrpcInterface/RiaGrpcPdmObjectService.cpp index 3583ec515d0..d32257a100a 100644 --- a/GrpcInterface/RiaGrpcPdmObjectService.cpp +++ b/GrpcInterface/RiaGrpcPdmObjectService.cpp @@ -568,7 +568,16 @@ grpc::Status RiaGrpcPdmObjectService::CallPdmObjectMethod( grpc::ServerContext* caf::PdmObjectMethodFactory::instance()->createMethod( matchingObject, methodKeyword ); if ( method ) { - copyPdmObjectFromRipsToCaf( &( request->params() ), method.get() ); + if ( auto result = copyPdmObjectFromRipsToCaf( &( request->params() ), method.get() ); !result ) + { + telemetryAttributes["pdm.status"] = "failed"; + telemetryAttributes["pdm.error"] = result.error().toStdString(); + RiaOpenTelemetryManager::instance().reportEventAsync( "grpc.pdm_method_call", telemetryAttributes ); + + RiaLogging::error( + QString( "Method '%1' failed. Error: %2" ).arg( methodKeyword ).arg( result.error() ).toStdString() ); + return grpc::Status( grpc::INVALID_ARGUMENT, result.error().toStdString() ); + } // clang-tidy-19 has a bug that did the following: // std::expected result = method->execute();