[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).
main
Adriaan de Groot 6 years ago
parent c9447d7794
commit 7149b80146

@ -21,16 +21,16 @@
namespace Calamares namespace Calamares
{ {
JobResult::JobResult( JobResult&& rhs ) : JobResult::JobResult( JobResult&& rhs )
m_ok( rhs.m_ok ) : m_message( std::move( rhs.m_message ) )
, m_message( std::move( rhs.m_message ) )
, m_details( std::move( rhs.m_details ) ) , m_details( std::move( rhs.m_details ) )
, m_number( rhs.m_number )
{ {
} }
JobResult::operator bool() const JobResult::operator bool() const
{ {
return m_ok; return m_number == 0;
} }
@ -64,21 +64,26 @@ JobResult::setDetails( const QString& details )
JobResult JobResult
JobResult::ok() JobResult::ok()
{ {
return JobResult( true, QString(), QString() ); return JobResult( QString(), QString(), NoError );
} }
JobResult JobResult
JobResult::error( const QString& message, const QString& details ) 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 ) JobResult::JobResult( const QString& message, const QString& details, int number )
: m_ok( ok ) : m_message( message )
, m_message( message )
, m_details( details ) , m_details( details )
, m_number( number )
{} {}

@ -29,6 +29,13 @@ namespace Calamares {
class DLLEXPORT JobResult class DLLEXPORT JobResult
{ {
public: public:
enum
{
NoError = 0,
GenericError = -1,
PythonUncaughtException = 1
} ;
JobResult( const JobResult& rhs ) = delete; JobResult( const JobResult& rhs ) = delete;
JobResult( JobResult&& rhs ); JobResult( JobResult&& rhs );
@ -42,17 +49,20 @@ public:
virtual QString details() const; virtual QString details() const;
virtual void setDetails( const QString& details ); virtual void setDetails( const QString& details );
/// @brief an "ok status" result
static JobResult ok(); static JobResult ok();
/// @brief an "error" result resulting from the execution of the job
static JobResult error( const QString& message, const QString& details = QString() ); 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: protected:
explicit JobResult( bool ok, const QString& message, const QString& details ); explicit JobResult( const QString& message, const QString& details, int errorCode );
private: private:
bool m_ok;
QString m_message; QString m_message;
QString m_details; QString m_details;
int m_number;
}; };
class DLLEXPORT Job : public QObject class DLLEXPORT Job : public QObject

@ -373,8 +373,10 @@ PythonJob::exec()
} }
bp::handle_exception(); bp::handle_exception();
PyErr_Clear(); PyErr_Clear();
return JobResult::error( tr( "Boost.Python error in job \"%1\"." ).arg( prettyName() ), return JobResult::internalError(
msg ); tr( "Boost.Python error in job \"%1\"." ).arg( prettyName() ),
msg,
JobResult::PythonUncaughtException );
} }
} }

@ -36,7 +36,7 @@ public:
const QString& message, const QString& message,
const QString& details ) const QString& details )
: QObject( nullptr ) : QObject( nullptr )
, Calamares::JobResult( ok, message, details ) , Calamares::JobResult( message, details, ok ? 0 : Calamares::JobResult::GenericError )
{} {}
}; };

Loading…
Cancel
Save