From 7149b80146b85ea843356b59a47d2c86577b404e Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sun, 28 Apr 2019 10:14:14 -0400 Subject: [PATCH] [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). --- src/libcalamares/Job.cpp | 23 +++++++++++++--------- src/libcalamares/Job.h | 16 ++++++++++++--- src/libcalamares/PythonJob.cpp | 6 ++++-- src/libcalamaresui/viewpages/PythonQtJob.h | 2 +- 4 files changed, 32 insertions(+), 15 deletions(-) diff --git a/src/libcalamares/Job.cpp b/src/libcalamares/Job.cpp index b5d626854..ded0aecc3 100644 --- a/src/libcalamares/Job.cpp +++ b/src/libcalamares/Job.cpp @@ -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 ) {} diff --git a/src/libcalamares/Job.h b/src/libcalamares/Job.h index 040ead6ad..eb685ff81 100644 --- a/src/libcalamares/Job.h +++ b/src/libcalamares/Job.h @@ -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 diff --git a/src/libcalamares/PythonJob.cpp b/src/libcalamares/PythonJob.cpp index 6e8323e49..32792e737 100644 --- a/src/libcalamares/PythonJob.cpp +++ b/src/libcalamares/PythonJob.cpp @@ -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 ); } } diff --git a/src/libcalamaresui/viewpages/PythonQtJob.h b/src/libcalamaresui/viewpages/PythonQtJob.h index f356e85cc..2b50c0ded 100644 --- a/src/libcalamaresui/viewpages/PythonQtJob.h +++ b/src/libcalamaresui/viewpages/PythonQtJob.h @@ -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 ) {} };