mirror of https://github.com/djcb/mu.git
mu-error: encode retval/flags in enum
This commit is contained in:
parent
9b3979219e
commit
34c5ca1627
|
@ -28,28 +28,40 @@
|
||||||
namespace Mu {
|
namespace Mu {
|
||||||
|
|
||||||
struct Error final : public std::exception {
|
struct Error final : public std::exception {
|
||||||
enum struct Code {
|
|
||||||
AccessDenied = 100, // don't overlap with MuError
|
// 16 lower bits are for the error code the next 8 bits is for the return code
|
||||||
AssertionFailure,
|
// upper byte is for flags
|
||||||
Command,
|
|
||||||
Crypto,
|
static constexpr uint32_t SoftError = 1 << 23;
|
||||||
File,
|
|
||||||
Index,
|
#define ERROR_ENUM(RV,CAT) \
|
||||||
Internal,
|
static_cast<uint32_t>(__LINE__ | ((RV) << 15) | (CAT))
|
||||||
InvalidArgument,
|
|
||||||
Message,
|
enum struct Code: uint32_t {
|
||||||
NoMatches,
|
AccessDenied = ERROR_ENUM(1,0),
|
||||||
NotFound,
|
AssertionFailure = ERROR_ENUM(1,0),
|
||||||
Parsing,
|
Command = ERROR_ENUM(1,0),
|
||||||
Play,
|
ContactNotFound = ERROR_ENUM(2,SoftError),
|
||||||
Query,
|
Crypto = ERROR_ENUM(1,0),
|
||||||
SchemaMismatch,
|
File = ERROR_ENUM(1,0),
|
||||||
Store,
|
Index = ERROR_ENUM(1,0),
|
||||||
UnverifiedSignature,
|
Internal = ERROR_ENUM(1,0),
|
||||||
User,
|
InvalidArgument = ERROR_ENUM(1,0),
|
||||||
Xapian,
|
Message = ERROR_ENUM(1,0),
|
||||||
|
NoMatches = ERROR_ENUM(4,SoftError),
|
||||||
|
NotFound = ERROR_ENUM(1,0),
|
||||||
|
Parsing = ERROR_ENUM(1,0),
|
||||||
|
Play = ERROR_ENUM(1,0),
|
||||||
|
Query = ERROR_ENUM(1,0),
|
||||||
|
SchemaMismatch = ERROR_ENUM(1,0),
|
||||||
|
Store = ERROR_ENUM(1,0),
|
||||||
|
StoreLock = ERROR_ENUM(19,0),
|
||||||
|
UnverifiedSignature = ERROR_ENUM(1,0),
|
||||||
|
User = ERROR_ENUM(1,0),
|
||||||
|
Xapian = ERROR_ENUM(1,0),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct an error
|
* Construct an error
|
||||||
*
|
*
|
||||||
|
@ -127,6 +139,21 @@ struct Error final : public std::exception {
|
||||||
*/
|
*/
|
||||||
Code code() const noexcept { return code_; }
|
Code code() const noexcept { return code_; }
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is this is a 'soft error'?
|
||||||
|
*
|
||||||
|
* @return true or false
|
||||||
|
*/
|
||||||
|
constexpr bool is_soft_error() const {
|
||||||
|
return (static_cast<uint32_t>(code_) & SoftError) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr uint8_t exit_code() const {
|
||||||
|
return ((static_cast<uint32_t>(code_) >> 15) & 0xf);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fill a GError with the error information
|
* Fill a GError with the error information
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue