@@ -24,16 +24,22 @@ extern "C" {
2424
2525// Error codes for TensorFlow Lite Task Library C APIs.
2626//
27- // One to one mapping with `TfLiteSupportStatus` code starting from kError = 1.
28- // Omits `kOk` since `TfLiteErrorCode` is only to be used in the event of an
29- // error and does not account for success unlike `TfLiteSupportStatus`. In case
30- // of success, TensorFlow Lite Task Library C APIs return the appropriate return
31- // value and a null error. One to one mapping makes it easier to convert between
32- // `TfLiteSupportStatus` and `TfLiteSupportErrorCode` without long switch statements.
33- // kErrorCodeFirst and kErrorCodeLast are also provided for safety checks during
34- // conversion. In case of modifications in error codes, ensure that
35- // kErrorCodeFirst is set to the least enum value and kErrorCodeLast is set to
36- // the greatest enum value.
27+ // Holds one to one mapping with `TfLiteSupportStatus` code starting from kError
28+ // = 1. Omits `kOk` since `TfLiteErrorCode` is only to be used in the event of
29+ // an error and does not account for success unlike `TfLiteSupportStatus`. In
30+ // case of success, TensorFlow Lite Task Library C APIs return the appropriate
31+ // return value and a null error. One to one mapping makes it easier to convert
32+ // between `TfLiteSupportStatus` and `TfLiteSupportErrorCode` without long
33+ // switch statements.
34+ //
35+ // Also holds error codes mapping to absl::Status::code() starting from
36+ // kNotFound = 900 in cases where the absl::Status payload can't
37+ // be mapped to a `TfLiteSupportStatus` code. kErrorCodeFirst and kErrorCodeLast
38+ // are also provided for safety checks during conversion between
39+ // `TfLiteSupportStatus` and `TfLiteSupportErrorCode`. In case of modifications
40+ // in error codes, ensure that kErrorCodeFirst and kErrorCodeLast is
41+ // respectively, set to the least and greatest enum value amongst the error
42+ // codes mapping to TfLiteSupportStatus.
3743enum TfLiteSupportErrorCode {
3844 // Unspecified error.
3945 kError = 1 ,
@@ -144,17 +150,43 @@ enum TfLiteSupportErrorCode {
144150 kImageProcessingBackendError ,
145151
146152 // Convenience error codes for condition checks during type casting.
147-
148- // Ensure it holds the least enum value.
153+ //
154+ // Codes mapping to absl status codes should not be considered for these
155+ // ranges.
156+ // They must be used exclsively for checking if error codes fall in valid
157+ // ranges when converting between TfLiteSupportStatus and
158+ // TfLiteSupportErrorCodee.
159+
160+ // Ensure it holds the least enum value amongst error codes mapping to
161+ // TfLiteSupportStatus.
149162 kErrorCodeFirst = kError ,
150- // Ensure it holds the greatest enum value.
163+ // Ensure it holds the greatest enum value amongst error codes mapping to
164+ // TfLiteSupportStatus.
151165 kErrorCodeLast = kImageProcessingBackendError ,
152166
167+ // Absl Status Codes Mapping
168+ //
169+ // Codes starting from 900 will be used to map absl::Status created by TfLite
170+ // and are used as is by TfLite Support C++ layer. Such absl status objects
171+ // don't have a TfLiteSupportStatus in the payload that can be mapped to other
172+ // error codes in this struct. You must use the absl::Status::code() and map
173+ // them to the following error codes in such cases.
174+ // For more info on respective absl status codes, please see:
175+ // https://github.com/abseil/abseil-cpp/blob/master/absl/status/status.h#L91
176+
177+ // kNotFound indicates some requested entity (such as a file or directory)
178+ // was not found.
179+ kNotFound = 900 ,
180+ // kInternal indicates an internal error has occurred
181+ // and some invariants expected by the underlying system have not been
182+ // satisfied. This error code is reserved for serious errors.
183+ kInternal ,
184+
153185};
154186
155- // A `TfLiteSupportError` encapsulates an error code and a descriptive message to
156- // return in the event of an error being encountered in any TensorFlow Lite Task
157- // Library C API.
187+ // A `TfLiteSupportError` encapsulates an error code and a descriptive message
188+ // to return in the event of an error being encountered in any TensorFlow Lite
189+ // Task Library C API.
158190typedef struct TfLiteSupportError {
159191 // Holds the error code.
160192 enum TfLiteSupportErrorCode code ;
0 commit comments