Try to match the Python exception type with an appropriate Status code
| 61 | |
| 62 | // Try to match the Python exception type with an appropriate Status code |
| 63 | StatusCode MapPyError(PyObject* exc_type) { |
| 64 | StatusCode code; |
| 65 | |
| 66 | if (PyErr_GivenExceptionMatches(exc_type, PyExc_MemoryError)) { |
| 67 | code = StatusCode::OutOfMemory; |
| 68 | } else if (PyErr_GivenExceptionMatches(exc_type, PyExc_IndexError)) { |
| 69 | code = StatusCode::IndexError; |
| 70 | } else if (PyErr_GivenExceptionMatches(exc_type, PyExc_KeyError)) { |
| 71 | code = StatusCode::KeyError; |
| 72 | } else if (PyErr_GivenExceptionMatches(exc_type, PyExc_TypeError)) { |
| 73 | code = StatusCode::TypeError; |
| 74 | } else if (PyErr_GivenExceptionMatches(exc_type, PyExc_ValueError) || |
| 75 | PyErr_GivenExceptionMatches(exc_type, PyExc_OverflowError)) { |
| 76 | code = StatusCode::Invalid; |
| 77 | } else if (PyErr_GivenExceptionMatches(exc_type, PyExc_EnvironmentError)) { |
| 78 | code = StatusCode::IOError; |
| 79 | } else if (PyErr_GivenExceptionMatches(exc_type, PyExc_NotImplementedError)) { |
| 80 | code = StatusCode::NotImplemented; |
| 81 | } else { |
| 82 | code = StatusCode::UnknownError; |
| 83 | } |
| 84 | return code; |
| 85 | } |
| 86 | |
| 87 | // PythonErrorDetail indicates a Python exception was raised. |
| 88 | class PythonErrorDetail : public StatusDetail { |