diff --git a/src/libcalamares/ProcessJob.cpp b/src/libcalamares/ProcessJob.cpp index 9b3055671..fa467c08b 100644 --- a/src/libcalamares/ProcessJob.cpp +++ b/src/libcalamares/ProcessJob.cpp @@ -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 diff --git a/src/libcalamares/ProcessJob.h b/src/libcalamares/ProcessJob.h index 59a532023..a18bd1e3b 100644 --- a/src/libcalamares/ProcessJob.h +++ b/src/libcalamares/ProcessJob.h @@ -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,