Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Keep full stack trace in captured exception.
  • Loading branch information
viirya committed Oct 26, 2015
commit 0ccb4ae38b797c10dfea45d762932bb07d1d9d53
6 changes: 6 additions & 0 deletions python/pyspark/sql/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,12 @@ def test_capture_illegalargument_exception(self):
df = self.sqlCtx.createDataFrame([(1, 2)], ["a", "b"])
self.assertRaisesRegexp(IllegalArgumentException, "1024 is not in the permitted values",
lambda: df.select(sha2(df.a, 1024)).collect())
try:
df.select(sha2(df.a, 1024)).collect()
except IllegalArgumentException as e:
self.assertRegexpMatches(e.args[0], "1024 is not in the permitted values")
self.assertRegexpMatches(e.args[1],
"org.apache.spark.sql.functions")

def test_with_column_with_existing_name(self):
keys = self.df.withColumn("key", self.df.key).select("key").collect()
Expand Down
5 changes: 3 additions & 2 deletions python/pyspark/sql/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ def deco(*a, **kw):
return f(*a, **kw)
except py4j.protocol.Py4JJavaError as e:
s = e.java_exception.toString()
stackTrace = '\n'.join(map(lambda x: x.toString(), e.java_exception.getStackTrace()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'\n\t at ', make it looks like a Java stacktrace

if s.startswith('org.apache.spark.sql.AnalysisException: '):
raise AnalysisException(s.split(': ', 1)[1])
raise AnalysisException(s.split(': ', 1)[1], stackTrace)
if s.startswith('java.lang.IllegalArgumentException: '):
raise IllegalArgumentException(s.split(': ', 1)[1])
raise IllegalArgumentException(s.split(': ', 1)[1], stackTrace)
raise
return deco

Expand Down