bkietz commented on a change in pull request #7156:
URL: https://github.com/apache/arrow/pull/7156#discussion_r426713438



##########
File path: cpp/src/arrow/python/common.cc
##########
@@ -96,42 +109,38 @@ class PythonErrorDetail : public StatusDetail {
   }
 
   void RestorePyError() const {
-    Py_INCREF(exc_type_.obj());
-    Py_INCREF(exc_value_.obj());
-    Py_INCREF(exc_traceback_.obj());
-    PyErr_Restore(exc_type_.obj(), exc_value_.obj(), exc_traceback_.obj());
+    PyErr_Restore(exc_type_.incref(), exc_value_.incref(), 
exc_traceback_.incref());
   }
 
   PyObject* exc_type() const { return exc_type_.obj(); }
 
   PyObject* exc_value() const { return exc_value_.obj(); }
 
-  static std::shared_ptr<PythonErrorDetail> FromPyError() {
-    PyObject* exc_type = nullptr;
-    PyObject* exc_value = nullptr;
-    PyObject* exc_traceback = nullptr;
-
-    PyErr_Fetch(&exc_type, &exc_value, &exc_traceback);
-    PyErr_NormalizeException(&exc_type, &exc_value, &exc_traceback);
-    ARROW_CHECK(exc_type)
-        << "PythonErrorDetail::FromPyError called without a Python error set";
-    DCHECK(PyType_Check(exc_type));
-    DCHECK(exc_value);  // Ensured by PyErr_NormalizeException, double-check
-    if (exc_traceback == nullptr) {
-      // Needed by PyErr_Restore()
-      Py_INCREF(Py_None);
-      exc_traceback = Py_None;
+  Status ToStatus(StatusCode code = StatusCode::UnknownError) && {
+    if (code == StatusCode::UnknownError) {
+      code = MapPyError(exc_type());
     }
 
-    std::shared_ptr<PythonErrorDetail> detail(new PythonErrorDetail);
-    detail->exc_type_.reset(exc_type);
-    detail->exc_value_.reset(exc_value);
-    detail->exc_traceback_.reset(exc_traceback);
-    return detail;
+    std::string message;
+    RETURN_NOT_OK(internal::PyObject_StdStringStr(exc_value(), &message));
+
+    auto detail = std::make_shared<PythonErrorDetail>(std::move(*this));

Review comment:
       I'll try to make it prettier




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to