From 1f7dfafe9a2b8a99bcde5ec09349507d5f4f6c56 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sun, 28 Apr 2019 10:51:31 -0400 Subject: [PATCH] [libcalamares] Provide accessor to error code. - Document meaning of error codes. - The test-loader considers internal errors a real (test) failure, while errors returned normally by the modules (e.g. because the configuration is broken) to be ok for testing purposes. --- src/calamares/testmain.cpp | 3 ++- src/libcalamares/Job.cpp | 2 +- src/libcalamares/Job.h | 9 +++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/calamares/testmain.cpp b/src/calamares/testmain.cpp index 195701024..982a9b4c2 100644 --- a/src/calamares/testmain.cpp +++ b/src/calamares/testmain.cpp @@ -227,7 +227,8 @@ main( int argc, char* argv[] ) cError() << "Job #" << count << "failed" << TR( "summary", r.message() ) << TR( "details", r.details() ); - ++failure_count; + if ( r.errorCode() > 0 ) + ++failure_count; } ++count; } diff --git a/src/libcalamares/Job.cpp b/src/libcalamares/Job.cpp index ded0aecc3..d2118451f 100644 --- a/src/libcalamares/Job.cpp +++ b/src/libcalamares/Job.cpp @@ -71,7 +71,7 @@ JobResult::ok() JobResult JobResult::error( const QString& message, const QString& details ) { - return JobResult( message, details, -1 ); + return JobResult( message, details, GenericError ); } JobResult diff --git a/src/libcalamares/Job.h b/src/libcalamares/Job.h index eb685ff81..04b4560a4 100644 --- a/src/libcalamares/Job.h +++ b/src/libcalamares/Job.h @@ -29,6 +29,13 @@ namespace Calamares { class DLLEXPORT JobResult { public: + /** @brief Distinguish classes of errors + * + * All "ok result" have errorCode 0 (NoError). + * Errors returned from job execution have values < 0. + * Errors before job execution, or not returned by the job execution + * itself, have values > 0. + */ enum { NoError = 0, @@ -49,6 +56,8 @@ public: virtual QString details() const; virtual void setDetails( const QString& details ); + int errorCode() const { return m_number; } + /// @brief an "ok status" result static JobResult ok(); /// @brief an "error" result resulting from the execution of the job