[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.
This commit is contained in:
Adriaan de Groot 2019-04-28 10:51:31 -04:00
parent 7149b80146
commit 1f7dfafe9a
3 changed files with 12 additions and 2 deletions

View File

@ -227,7 +227,8 @@ main( int argc, char* argv[] )
cError() << "Job #" << count << "failed" cError() << "Job #" << count << "failed"
<< TR( "summary", r.message() ) << TR( "summary", r.message() )
<< TR( "details", r.details() ); << TR( "details", r.details() );
++failure_count; if ( r.errorCode() > 0 )
++failure_count;
} }
++count; ++count;
} }

View File

@ -71,7 +71,7 @@ JobResult::ok()
JobResult JobResult
JobResult::error( const QString& message, const QString& details ) JobResult::error( const QString& message, const QString& details )
{ {
return JobResult( message, details, -1 ); return JobResult( message, details, GenericError );
} }
JobResult JobResult

View File

@ -29,6 +29,13 @@ namespace Calamares {
class DLLEXPORT JobResult class DLLEXPORT JobResult
{ {
public: 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 enum
{ {
NoError = 0, NoError = 0,
@ -49,6 +56,8 @@ public:
virtual QString details() const; virtual QString details() const;
virtual void setDetails( const QString& details ); virtual void setDetails( const QString& details );
int errorCode() const { return m_number; }
/// @brief an "ok status" result /// @brief an "ok status" result
static JobResult ok(); static JobResult ok();
/// @brief an "error" result resulting from the execution of the job /// @brief an "error" result resulting from the execution of the job