arrow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From w...@apache.org
Subject arrow git commit: ARROW-866: [Python] Normalize PyErr exc_value to be more predictable
Date Sat, 06 May 2017 02:07:48 GMT
Repository: arrow
Updated Branches:
  refs/heads/master 316c63dba -> 5af8069d2


ARROW-866: [Python] Normalize PyErr exc_value to be more predictable

It is possible when using `PyErr_Fetch(&exc_type, &exc_value, &traceback)` for
the `exc_value` to be a string, tuple or NULL.  Calling `PyErr_Normalize` after this will
cause `exc_value` to always be a valid object of the same type as `exc_type` which can then
be converted to a string predictably.

Author: Bryan Cutler <cutlerb@gmail.com>

Closes #630 from BryanCutler/python-pyerr_normalize-ARROW866 and squashes the following commits:

fb93356 [Bryan Cutler] use PyObjectStringify to be Unicode safe
d56c6bf [Bryan Cutler] Added PyErr_NormalizeException to CheckPyError to make more predictable
exc_value


Project: http://git-wip-us.apache.org/repos/asf/arrow/repo
Commit: http://git-wip-us.apache.org/repos/asf/arrow/commit/5af8069d
Tree: http://git-wip-us.apache.org/repos/asf/arrow/tree/5af8069d
Diff: http://git-wip-us.apache.org/repos/asf/arrow/diff/5af8069d

Branch: refs/heads/master
Commit: 5af8069d234a7b16ab324085ecc802e6f915ae88
Parents: 316c63d
Author: Bryan Cutler <cutlerb@gmail.com>
Authored: Fri May 5 22:07:42 2017 -0400
Committer: Wes McKinney <wes.mckinney@twosigma.com>
Committed: Fri May 5 22:07:42 2017 -0400

----------------------------------------------------------------------
 cpp/src/arrow/python/common.cc | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/arrow/blob/5af8069d/cpp/src/arrow/python/common.cc
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/python/common.cc b/cpp/src/arrow/python/common.cc
index bedd458..5702c71 100644
--- a/cpp/src/arrow/python/common.cc
+++ b/cpp/src/arrow/python/common.cc
@@ -68,20 +68,16 @@ Status CheckPyError(StatusCode code) {
   if (PyErr_Occurred()) {
     PyObject *exc_type, *exc_value, *traceback;
     PyErr_Fetch(&exc_type, &exc_value, &traceback);
-    PyObjectStringify stringified(exc_value);
+    PyErr_NormalizeException(&exc_type, &exc_value, &traceback);
+    PyObject *exc_value_str = PyObject_Str(exc_value);
+    PyObjectStringify stringified(exc_value_str);
+    std::string message(stringified.bytes);
     Py_XDECREF(exc_type);
     Py_XDECREF(exc_value);
+    Py_XDECREF(exc_value_str);
     Py_XDECREF(traceback);
     PyErr_Clear();
-
-    // ARROW-866: in some esoteric cases, formatting exc_value can fail. This
-    // was encountered when calling tell() on a socket file
-    if (stringified.bytes != nullptr) {
-      std::string message(stringified.bytes);
-      return Status(code, message);
-    } else {
-      return Status(code, "Error message was null");
-    }
+    return Status(code, message);
   }
   return Status::OK();
 }


Mime
View raw message