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(BadVolumeIndex, "Volume index is invalid") \
57  XX(NotMounted, "File system is not mounted") \
58  XX(BadObject, "Malformed filesystem object") \
59  XX(BadFileSystem, "File system corruption detected") \
60  XX(BadParam, "Invalid parameter(s)") \
61  XX(NotImplemented, "File system or method not yet implemented") \
62  XX(NotSupported, "Parameter value not supported") \
63  XX(NoMem, "Memory allocation failed") \
64  XX(NameTooLong, "File name or path is too long for buffer") \
65  XX(BufferTooSmall, "Data is too long for buffer") \
66  XX(NotFound, "Object not found") \
67  XX(ReadOnly, "Media is read-only") \
68  XX(ReadFailure, "Media read failed") \
69  XX(WriteFailure, "Media write failed") \
70  XX(EraseFailure, "Media erase failed") \
71  XX(InvalidHandle, "File handle is outside valid range") \
72  XX(InvalidObjectRef, "Filesystem object reference invalid") \
73  XX(InvalidObject, "Filesystem object invalid") \
74  XX(EndOfObjects, "Last object in filing system has been read") \
75  XX(FileNotOpen, "File handle is valid but the file is not open") \
76  XX(SeekBounds, "seek would give an invalid file offset") \
77  XX(NoMoreFiles, "readdir has no more files to return") \
78  XX(OutOfFileDescs, "Cannot open another file until one is closed")
79 
80 enum class Value {
81 #define XX(tag, text) tag,
83 #undef XX
84  MAX, // Mark end of value range
85 };
86 
87 // Define the Error::xxx codes as negative versions of the enumerated values
88 #define XX(tag, text) constexpr int tag{-int(Value::tag)};
90 #undef XX
91 
92 constexpr ErrorCode USER{-100}; // Start of user-defined codes
93 constexpr ErrorCode SYSTEM{-1000}; // Non-FWFS filing systems map custom codes starting here
94 
100 String toString(int err);
101 
105 inline bool isSystem(int err)
106 {
107  return err <= SYSTEM;
108 }
109 
113 inline int fromSystem(int syscode)
114 {
115  return (syscode < 0) ? SYSTEM + syscode : syscode;
116 }
117 
121 inline int toSystem(int err)
122 {
123  return isSystem(err) ? (err - SYSTEM) : err;
124 }
125 
126 } // namespace Error
127 
128 constexpr ErrorCode FS_OK = Error::Success;
129 
130 } // 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:93
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:105
int fromSystem(int syscode)
Translate system error code into IFS error code.
Definition: Error.h:113
int toSystem(int err)
Translate IFS error code into SYSTEM code.
Definition: Error.h:121
constexpr ErrorCode USER
Definition: Error.h:92
Value
Definition: Error.h:80
constexpr ErrorCode FS_OK
Definition: Error.h:128