[libcalamares] Refactor explanation of process-job errors

This commit is contained in:
Adriaan de Groot 2017-12-21 16:30:13 +01:00
parent c6ab4195c7
commit f8a53f9646
2 changed files with 41 additions and 31 deletions

View File

@ -82,37 +82,7 @@ ProcessJob::exec()
QString(),
m_timeoutSec );
if ( ec == 0 )
return JobResult::ok();
if ( ec == -1 ) //Crash!
return JobResult::error( tr( "External command crashed" ),
tr( "Command %1 crashed.\nOutput:\n%2" )
.arg( m_command )
.arg( output ) );
if ( ec == -2 )
return JobResult::error( tr( "External command failed to start" ),
tr( "Command %1 failed to start." )
.arg( m_command ) );
if ( ec == -3 )
return JobResult::error( tr( "Internal error when starting command" ),
tr( "Bad parameters for process job call." ) );
if ( ec == -4 )
return JobResult::error( tr( "External command failed to finish" ),
tr( "Command %1 failed to finish in %2s.\nOutput:\n%3" )
.arg( m_command )
.arg( m_timeoutSec )
.arg( output ) );
//Any other exit code
return JobResult::error( tr( "External command finished with errors" ),
tr( "Command %1 finished with exit code %2.\nOutput:\n%3" )
.arg( m_command )
.arg( ec )
.arg( output ) );
return explainProcess( ec, m_command, output, m_timeoutSec );
}
@ -175,4 +145,40 @@ ProcessJob::callOutput( const QString& command,
}
JobResult
ProcessJob::explainProcess( int ec, const QString& command, const QString& output, int timeout )
{
if ( ec == 0 )
return JobResult::ok();
if ( ec == -1 ) //Crash!
return JobResult::error( tr( "External command crashed" ),
tr( "Command %1 crashed.\nOutput:\n%2" )
.arg( command )
.arg( output ) );
if ( ec == -2 )
return JobResult::error( tr( "External command failed to start" ),
tr( "Command %1 failed to start." )
.arg( command ) );
if ( ec == -3 )
return JobResult::error( tr( "Internal error when starting command" ),
tr( "Bad parameters for process job call." ) );
if ( ec == -4 )
return JobResult::error( tr( "External command failed to finish" ),
tr( "Command %1 failed to finish in %2s.\nOutput:\n%3" )
.arg( command )
.arg( timeout )
.arg( output ) );
//Any other exit code
return JobResult::error( tr( "External command finished with errors" ),
tr( "Command %1 finished with exit code %2.\nOutput:\n%3" )
.arg( command )
.arg( ec )
.arg( output ) );
}
} // namespace Calamares

View File

@ -39,6 +39,10 @@ public:
QString prettyStatusMessage() const override;
JobResult exec() override;
protected:
/** @brief Explain a typical external process failure. */
static JobResult explainProcess( int errorCode, const QString& command, const QString& output, int timeout );
private:
int callOutput( const QString& command,
QString& output,