• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #ifndef TENSORFLOW_LITE_PYTHON_INTERPRETER_WRAPPER_PYTHON_ERROR_REPORTER_H_
17 #define TENSORFLOW_LITE_PYTHON_INTERPRETER_WRAPPER_PYTHON_ERROR_REPORTER_H_
18 
19 #include <Python.h>
20 
21 #include <sstream>
22 #include <string>
23 
24 #include "tensorflow/lite/stateful_error_reporter.h"
25 
26 namespace tflite {
27 namespace interpreter_wrapper {
28 
29 class PythonErrorReporter : public tflite::StatefulErrorReporter {
30  public:
PythonErrorReporter()31   PythonErrorReporter() {}
32 
33   // Report an error message
34   int Report(const char* format, va_list args) override;
35 
36   // Sets a Python runtime exception with the last error and
37   // clears the error message buffer.
38   PyObject* exception();
39 
40   // Gets the last error message and clears the buffer.
41   std::string message() override;
42 
43  private:
44   std::stringstream buffer_;
45 };
46 
47 }  // namespace interpreter_wrapper
48 }  // namespace tflite
49 #endif  // TENSORFLOW_LITE_PYTHON_INTERPRETER_WRAPPER_PYTHON_ERROR_REPORTER_H_
50