mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-24 22:27:55 -05:00
#12940 Fix empty vector parsing and ReadPastEnd handling for Python GRPC
- Handle empty arrays [] in std::vector<cvf::Vec3d> parser - Only treat ReadCorruptData as error in generic template (ReadPastEnd is expected for types like caf::FilePath that consume all input) - Use strict mode (allowExtraCharacters=false) for Python GRPC parsing
This commit is contained in:
1 parent
6a1c74bdfc
commit
8b13dbcef1
3 files changed
+15
-18
No files matched your search
@@ -210,23 +210,11 @@ struct PdmFieldScriptingCapabilityIOHandler
|
||||
bool allowExtraCharacters = true )
|
||||
{
|
||||
inputStream >> fieldValue;
|
||||
if ( inputStream.status() != QTextStream::Ok )
|
||||
// Only report ReadCorruptData as an error. ReadPastEnd just means the stream was fully
|
||||
// consumed, which is expected for types like caf::FilePath that read all available input.
|
||||
if ( inputStream.status() == QTextStream::ReadCorruptData )
|
||||
{
|
||||
QString errorMessage;
|
||||
if ( inputStream.status() == QTextStream::ReadPastEnd )
|
||||
{
|
||||
errorMessage = "Read past end of argument";
|
||||
}
|
||||
else if ( inputStream.status() == QTextStream::ReadCorruptData )
|
||||
{
|
||||
errorMessage = "Argument value is unreadable";
|
||||
}
|
||||
else
|
||||
{
|
||||
errorMessage = "Unknown read error";
|
||||
}
|
||||
|
||||
errorMessageContainer->addError( errorMessage + ": \"" + errorMessageContainer->currentArgument +
|
||||
errorMessageContainer->addError( "Argument value is unreadable: \"" + errorMessageContainer->currentArgument +
|
||||
"\" in the command: \"" + errorMessageContainer->currentCommand + "\"" );
|
||||
inputStream.setStatus( QTextStream::Ok );
|
||||
}
|
||||
|
||||
@@ -99,6 +99,15 @@ void PdmFieldScriptingCapabilityIOHandler<std::vector<cvf::Vector3<double>>>::wr
|
||||
{
|
||||
while ( !inputStream.atEnd() )
|
||||
{
|
||||
// Check for closing bracket first (handles empty array case)
|
||||
errorMessageContainer->skipWhiteSpaceWithLineNumberCount( inputStream );
|
||||
QChar nextChar = errorMessageContainer->peekNextChar( inputStream );
|
||||
if ( nextChar == QChar( ']' ) )
|
||||
{
|
||||
nextChar = errorMessageContainer->readCharWithLineNumberCount( inputStream );
|
||||
break;
|
||||
}
|
||||
|
||||
std::vector<double> fieldVectorValue;
|
||||
|
||||
PdmFieldScriptingCapabilityIOHandler<std::vector<double>>::writeToField( fieldVectorValue,
|
||||
@@ -120,7 +129,7 @@ void PdmFieldScriptingCapabilityIOHandler<std::vector<cvf::Vector3<double>>>::wr
|
||||
}
|
||||
|
||||
errorMessageContainer->skipWhiteSpaceWithLineNumberCount( inputStream );
|
||||
QChar nextChar = errorMessageContainer->peekNextChar( inputStream );
|
||||
nextChar = errorMessageContainer->peekNextChar( inputStream );
|
||||
if ( nextChar == QChar( ']' ) )
|
||||
{
|
||||
nextChar = errorMessageContainer->readCharWithLineNumberCount( inputStream );
|
||||
|
||||
@@ -282,7 +282,7 @@ std::expected<void, QString> RiaGrpcServiceInterface::assignFieldValue( const QS
|
||||
// Step 1: Save old value for potential rollback
|
||||
if ( valueField ) *oldValue = valueField->toQVariant();
|
||||
|
||||
// Step 2: Parse and set new value
|
||||
// Step 2: Parse and set new value (strict mode for GRPC)
|
||||
QTextStream stream( stringValue.toLatin1() );
|
||||
scriptability->writeToField( stream, nullptr, messages, false, RimProject::current(), false );
|
||||
|
||||
|
||||
Reference in new issue
Block a user