[libcalamares] Distinguish kinds of errors
- errors can now carry an integer what-am-I code apart from the message; all errors have a code != 0 (and ok has code 0).
This commit is contained in:
parent
c9447d7794
commit
7149b80146
@ -21,16 +21,16 @@
|
||||
namespace Calamares
|
||||
{
|
||||
|
||||
JobResult::JobResult( JobResult&& rhs ) :
|
||||
m_ok( rhs.m_ok )
|
||||
, m_message( std::move( rhs.m_message ) )
|
||||
JobResult::JobResult( JobResult&& rhs )
|
||||
: m_message( std::move( rhs.m_message ) )
|
||||
, m_details( std::move( rhs.m_details ) )
|
||||
, m_number( rhs.m_number )
|
||||
{
|
||||
}
|
||||
|
||||
JobResult::operator bool() const
|
||||
{
|
||||
return m_ok;
|
||||
return m_number == 0;
|
||||
}
|
||||
|
||||
|
||||
@ -64,21 +64,26 @@ JobResult::setDetails( const QString& details )
|
||||
JobResult
|
||||
JobResult::ok()
|
||||
{
|
||||
return JobResult( true, QString(), QString() );
|
||||
return JobResult( QString(), QString(), NoError );
|
||||
}
|
||||
|
||||
|
||||
JobResult
|
||||
JobResult::error( const QString& message, const QString& details )
|
||||
{
|
||||
return JobResult( false, message, details );
|
||||
return JobResult( message, details, -1 );
|
||||
}
|
||||
|
||||
JobResult
|
||||
JobResult::internalError( const QString& message, const QString& details, int number )
|
||||
{
|
||||
return JobResult( message, details, number ? number : GenericError );
|
||||
}
|
||||
|
||||
JobResult::JobResult( bool ok, const QString& message, const QString& details )
|
||||
: m_ok( ok )
|
||||
, m_message( message )
|
||||
JobResult::JobResult( const QString& message, const QString& details, int number )
|
||||
: m_message( message )
|
||||
, m_details( details )
|
||||
, m_number( number )
|
||||
{}
|
||||
|
||||
|
||||
|
@ -29,6 +29,13 @@ namespace Calamares {
|
||||
class DLLEXPORT JobResult
|
||||
{
|
||||
public:
|
||||
enum
|
||||
{
|
||||
NoError = 0,
|
||||
GenericError = -1,
|
||||
PythonUncaughtException = 1
|
||||
} ;
|
||||
|
||||
JobResult( const JobResult& rhs ) = delete;
|
||||
JobResult( JobResult&& rhs );
|
||||
|
||||
@ -42,17 +49,20 @@ public:
|
||||
virtual QString details() const;
|
||||
virtual void setDetails( const QString& details );
|
||||
|
||||
/// @brief an "ok status" result
|
||||
static JobResult ok();
|
||||
|
||||
/// @brief an "error" result resulting from the execution of the job
|
||||
static JobResult error( const QString& message, const QString& details = QString() );
|
||||
/// @brief an "internal error" meaning the job itself has a problem (usually for python)
|
||||
static JobResult internalError( const QString&, const QString& details, int errorCode );
|
||||
|
||||
protected:
|
||||
explicit JobResult( bool ok, const QString& message, const QString& details );
|
||||
explicit JobResult( const QString& message, const QString& details, int errorCode );
|
||||
|
||||
private:
|
||||
bool m_ok;
|
||||
QString m_message;
|
||||
QString m_details;
|
||||
int m_number;
|
||||
};
|
||||
|
||||
class DLLEXPORT Job : public QObject
|
||||
|
@ -373,8 +373,10 @@ PythonJob::exec()
|
||||
}
|
||||
bp::handle_exception();
|
||||
PyErr_Clear();
|
||||
return JobResult::error( tr( "Boost.Python error in job \"%1\"." ).arg( prettyName() ),
|
||||
msg );
|
||||
return JobResult::internalError(
|
||||
tr( "Boost.Python error in job \"%1\"." ).arg( prettyName() ),
|
||||
msg,
|
||||
JobResult::PythonUncaughtException );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ public:
|
||||
const QString& message,
|
||||
const QString& details )
|
||||
: QObject( nullptr )
|
||||
, Calamares::JobResult( ok, message, details )
|
||||
, Calamares::JobResult( message, details, ok ? 0 : Calamares::JobResult::GenericError )
|
||||
{}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user