[libcalamares] Produce warnings while reading settings

- any invalid instance key will cause a complaint
- "new" custom instances in sequence get a complaint, but
  the instance description added to the list is valid
This commit is contained in:
Adriaan de Groot 2020-08-11 15:49:14 +02:00
parent a8075fba5f
commit 4cd2a4ae91
2 changed files with 20 additions and 8 deletions

View File

@ -169,7 +169,13 @@ interpretInstances( const YAML::Node& node, Settings::InstanceDescriptionList& c
{ {
continue; continue;
} }
customInstances.append( InstanceDescription::fromSettings( instancesVListItem.toMap() ) ); auto description = InstanceDescription::fromSettings( instancesVListItem.toMap() );
if ( !description.isValid() )
{
cWarning() << "Invalid entry in *instances*" << instancesVListItem;
}
// Append it **anyway**, since this will bail out after Settings is constructed
customInstances.append( description );
} }
} }
} }
@ -206,16 +212,22 @@ interpretSequence( const YAML::Node& node, Settings::ModuleSequence& moduleSeque
} }
else else
{ {
cDebug() << "Unknown action in *sequence*" << thisActionS;
continue; continue;
} }
QStringList thisActionRoster = sequenceVListItem.toMap().value( thisActionS ).toStringList(); QStringList thisActionRoster = sequenceVListItem.toMap().value( thisActionS ).toStringList();
Calamares::ModuleSystem::InstanceKeyList roster; Calamares::ModuleSystem::InstanceKeyList roster;
roster.reserve( thisActionRoster.count() ); roster.reserve( thisActionRoster.count() );
std::transform( thisActionRoster.constBegin(), for ( const auto& s : thisActionRoster )
thisActionRoster.constEnd(), {
std::back_inserter( roster ), auto instanceKey = Calamares::ModuleSystem::InstanceKey::fromString( s );
[]( const QString& s ) { return Calamares::ModuleSystem::InstanceKey::fromString( s ); } ); if ( !instanceKey.isValid() )
{
cWarning() << "Invalid instance in *sequence*" << s;
}
roster.append( instanceKey );
}
moduleSequence.append( qMakePair( thisAction, roster ) ); moduleSequence.append( qMakePair( thisAction, roster ) );
} }
} }
@ -258,7 +270,7 @@ Settings::Settings( const QString& settingsFilePath, bool debugMode )
} }
void void
Settings::validateSequence() Settings::reconcileInstancesAndSequence()
{ {
// Since moduleFinder captures targetKey by reference, we can // Since moduleFinder captures targetKey by reference, we can
// update targetKey to change what the finder lambda looks for. // update targetKey to change what the finder lambda looks for.
@ -311,7 +323,7 @@ Settings::setConfiguration( const QByteArray& ba, const QString& explainName )
m_disableCancelDuringExec = requireBool( config, "disable-cancel-during-exec", false ); m_disableCancelDuringExec = requireBool( config, "disable-cancel-during-exec", false );
m_quitAtEnd = requireBool( config, "quit-at-end", false ); m_quitAtEnd = requireBool( config, "quit-at-end", false );
validateSequence(); reconcileInstancesAndSequence();
} }
catch ( YAML::Exception& e ) catch ( YAML::Exception& e )
{ {

View File

@ -89,7 +89,7 @@ public:
explicit Settings( const QString& settingsFilePath, bool debugMode ); explicit Settings( const QString& settingsFilePath, bool debugMode );
void setConfiguration( const QByteArray& configData, const QString& explainName ); void setConfiguration( const QByteArray& configData, const QString& explainName );
void validateSequence(); void reconcileInstancesAndSequence();
public: public:
static Settings* instance(); static Settings* instance();