Error.h
Go to the documentation of this file.
1 
29 #pragma once
30 
31 #include "Types.h"
32 
33 namespace IFS
34 {
35 using ErrorCode = int;
36 
37 namespace Error
38 {
51 #define IFS_ERROR_MAP(XX) \
52  XX(Success, "Success") \
53  XX(NoFileSystem, "File system has not been set") \
54  XX(NoPartition, "Partition not found / undefined") \
55  XX(BadPartition, "Partition is not valid for this filesystem") \
56  XX(BadStore, "Store is invalid") \
57  XX(StoreNotMounted, "Store not mounted") \
58  XX(NotMounted, "File system is not mounted") \
59  XX(BadObject, "Malformed filesystem object") \
60  XX(BadFileSystem, "File system corruption detected") \
61  XX(BadParam, "Invalid parameter(s)") \
62  XX(BadExtent, "Invalid media extent") \
63  XX(NotImplemented, "File system or method not yet implemented") \
64  XX(NotSupported, "Parameter value not supported") \
65  XX(NoMem, "Memory allocation failed") \
66  XX(NameTooLong, "File name or path is too long for buffer") \
67  XX(BufferTooSmall, "Data is too long for buffer") \
68  XX(NotFound, "Object not found") \
69  XX(ReadOnly, "Media is read-only") \
70  XX(ReadFailure, "Media read failed") \
71  XX(WriteFailure, "Media write failed") \
72  XX(EraseFailure, "Media erase failed") \
73  XX(InvalidHandle, "File handle is outside valid range") \
74  XX(InvalidObjectRef, "Filesystem object reference invalid") \
75  XX(InvalidObject, "Filesystem object invalid") \
76  XX(EndOfObjects, "Last object in filing system has been read") \
77  XX(FileNotOpen, "File handle is valid but the file is not open") \
78  XX(SeekBounds, "seek would give an invalid file offset") \
79  XX(NoMoreFiles, "readdir has no more files to return") \
80  XX(OutOfFileDescs, "Cannot open another file until one is closed")
81 
82 enum class Value {
83 #define XX(tag, text) tag,
85 #undef XX
86  MAX, // Mark end of value range
87 };
88 
89 // Define the Error::xxx codes as negative versions of the enumerated values
90 #define XX(tag, text) constexpr int tag{-int(Value::tag)};
92 #undef XX
93 
94 constexpr ErrorCode USER{-100}; // Start of user-defined codes
95 constexpr ErrorCode SYSTEM{-1000}; // Non-FWFS filing systems map custom codes starting here
96 
102 String toString(int err);
103 
107 inline bool isSystem(int err)
108 {
109  return err <= SYSTEM;
110 }
111 
115 inline int fromSystem(int syscode)
116 {
117  return (syscode < 0) ? SYSTEM + syscode : syscode;
118 }
119 
123 inline int toSystem(int err)
124 {
125  return isSystem(err) ? (err - SYSTEM) : err;
126 }
127 
128 } // namespace Error
129 
130 constexpr ErrorCode FS_OK = Error::Success;
131 
132 } // namespace IFS
#define IFS_ERROR_MAP(XX)
IFS return codes.
Definition: Error.h:51
The String class.
Definition: WString.h:136
constexpr ErrorCode SYSTEM
Definition: Error.h:95
Error
Definition: Libraries/HueEmulator/src/include/Hue/Device.h:51
String toString(int err)
get text for an error code
Definition: DirectoryTemplate.h:36
bool isSystem(int err)
Determine if the given IFS error code is system-specific.
Definition: Error.h:107
int fromSystem(int syscode)
Translate system error code into IFS error code.
Definition: Error.h:115
int toSystem(int err)
Translate IFS error code into SYSTEM code.
Definition: Error.h:123
constexpr ErrorCode USER
Definition: Error.h:94
Value
Definition: Error.h:82
constexpr ErrorCode FS_OK
Definition: Error.h:130