/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ #ifndef TENSORFLOW_LITE_SUPPORT_CC_COMMON_H_ #define TENSORFLOW_LITE_SUPPORT_CC_COMMON_H_ #include "absl/status/status.h" // from @com_google_absl #include "absl/strings/string_view.h" // from @com_google_absl namespace tflite { namespace support { // Name (aka type URL key) of the `absl::Status` payload which contains a // stringified `TfLiteSupportStatus` code (see below). constexpr absl::string_view kTfLiteSupportPayload = …; // Error codes for TensorFlow Lite Support (TFLS) C++ APIs. // // Such codes capture errors encountered in the TFLS layer. They complement all // the other type of errors that occur in the lower-level TF Lite codebase (see // `TfLiteStatus` codes). // // At runtime, such codes are meant to be attached (where applicable) to a // `absl::Status` in a key-value manner with `kTfLiteSupportPayload` as key and // stringifed error code as value (aka payload). This logic is encapsulated in // the `CreateStatusWithPayload` helper below for convenience. // // The returned status includes: // 1. The canonical error code (INVALID_ARGUMENT) // 2. The fine-grained error message ("Invalid metadata ...") // 3. The specific TFLS code as a payload (kMetadataInvalidSchemaVersionError) enum class TfLiteSupportStatus { … }; // Convenience helper to create an `absl::Status` augmented with the // fine-grained `tfls_code` attached as payload under the // `kTfLiteSupportPayload` type URL key. // // This should only be used for non-ok codes since otherwise it does nothing // more than returning an object identical to an OK status. See `absl::Status` // for more details. absl::Status CreateStatusWithPayload( absl::StatusCode canonical_code, absl::string_view message, tflite::support::TfLiteSupportStatus tfls_code = tflite::support::TfLiteSupportStatus::kError); } // namespace support } // namespace tflite #endif // TENSORFLOW_LITE_SUPPORT_CC_COMMON_H_