GH-1411 fail if pre-launch and post-exit commands return non-zero values

This commit is contained in:
Petr Mrázek 2016-01-20 03:23:19 +01:00
parent 9fd66b3bb1
commit 5ecaed21b5
2 changed files with 34 additions and 7 deletions

View File

@ -34,20 +34,34 @@ void PostLaunchCommand::executeTask()
void PostLaunchCommand::on_state(LoggedProcess::State state)
{
auto getError = [&]()
{
return tr("Post-Launch command failed with code %1.\n\n").arg(m_process.exitCode());
};
switch(state)
{
case LoggedProcess::Aborted:
case LoggedProcess::Crashed:
case LoggedProcess::FailedToStart:
{
QString error = tr("Post-Launch command failed with code %1.\n\n").arg(m_process.exitCode());
emit logLine(error, MessageLevel::Error);
auto error = getError();
emit logLine(error, MessageLevel::Fatal);
emitFailed(error);
return;
}
case LoggedProcess::Finished:
{
emit logLine(tr("Post-Launch command ran successfully.\n\n"), MessageLevel::MultiMC);
emitSucceeded();
if(m_process.exitCode() != 0)
{
auto error = getError();
emit logLine(error, MessageLevel::Fatal);
emitFailed(error);
}
else
{
emit logLine(tr("Post-Launch command ran successfully.\n\n"), MessageLevel::MultiMC);
emitSucceeded();
}
}
default:
break;

View File

@ -35,21 +35,34 @@ void PreLaunchCommand::executeTask()
void PreLaunchCommand::on_state(LoggedProcess::State state)
{
auto getError = [&]()
{
return tr("Pre-Launch command failed with code %1.\n\n").arg(m_process.exitCode());
};
switch(state)
{
case LoggedProcess::Aborted:
case LoggedProcess::Crashed:
case LoggedProcess::FailedToStart:
{
QString error = tr("Pre-Launch command failed with code %1.\n\n").arg(m_process.exitCode());
auto error = getError();
emit logLine(error, MessageLevel::Fatal);
emitFailed(error);
return;
}
case LoggedProcess::Finished:
{
emit logLine(tr("Pre-Launch command ran successfully.\n\n"), MessageLevel::MultiMC);
emitSucceeded();
if(m_process.exitCode() != 0)
{
auto error = getError();
emit logLine(error, MessageLevel::Fatal);
emitFailed(error);
}
else
{
emit logLine(tr("Pre-Launch command ran successfully.\n\n"), MessageLevel::MultiMC);
emitSucceeded();
}
}
default:
break;