Refactor RifFormationNamesReader to return std::expected

Replace the QString* errorMessage out-parameter with std::expected<RigFormationNames, QString> in RifFormationNamesReader, and propagate the pattern to RimFormationNames::readFormationNamesFile() which now returns std::expected<void, QString>.

Fatal errors (file cannot be opened, FMU line-parse failure) return std::unexpected. Malformed .lyr lines are still skipped so the rest of the file loads, with warnings logged via RiaLogging instead of collected in the out-parameter. RimFormationNamesCollection::readAllFormationNames() now logs errors it previously discarded.
This commit is contained in:
Kristian Bendiksen
2026-08-05 16:03:42 +02:00
parent db36c761dd
commit d87a0d3048
9 changed files with 66 additions and 75 deletions
@@ -46,7 +46,10 @@ void RimFormationNamesCollection::readAllFormationNames()
{
for ( RimFormationNames* fmNames : m_formationNamesList )
{
fmNames->readFormationNamesFile( nullptr );
if ( auto result = fmNames->readFormationNamesFile(); !result )
{
RiaLogging::error( result.error().toStdString() );
}
RimProject::current()->colorLegendCollection->createColorLegendFromFormationNames( fmNames );
}
}
@@ -90,12 +93,9 @@ std::vector<RimFormationNames*> RimFormationNamesCollection::importFiles( const
for ( RimFormationNames* fmNames : formNamesObjsToReload )
{
QString errormessage;
fmNames->readFormationNamesFile( &errormessage );
if ( !errormessage.isEmpty() )
if ( auto result = fmNames->readFormationNamesFile(); !result )
{
totalErrorMessage += "\nError in: " + fmNames->fileName() + "\n\t" + errormessage;
totalErrorMessage += "\nError in: " + fmNames->fileName() + "\n\t" + result.error();
}
}