mirror of
https://github.com/OPM/ResInsight.git
synced 2026-08-27 05:37:21 -05:00
#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:
@@ -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 {};
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -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 );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user