Skip to content

[FLINK-22470][python] Make sure that the root cause of the exception encountered during compiling the job was exposed to users in all cases #15766

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
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
25 changes: 8 additions & 17 deletions flink-python/pyflink/util/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@


class JavaException(Exception):
def __init__(self, msg, stack_trace):
self.msg = msg
def __init__(self, stack_trace: str):
self.stack_trace = stack_trace

def __str__(self):
return self.msg + "\n\t at " + self.stack_trace
return self.stack_trace


class TableException(JavaException):
Expand Down Expand Up @@ -150,12 +149,9 @@ def deco(*a, **kw):
get_gateway().jvm.org.apache.flink.client.python.PythonEnvUtils\
.setPythonException(e.java_exception)
s = e.java_exception.toString()
stack_trace = '\n\t at '.join(map(lambda x: x.toString(),
e.java_exception.getStackTrace()))
for exception in exception_mapping.keys():
if s.startswith(exception):
java_exception = \
exception_mapping[exception](s.split(': ', 1)[1], stack_trace)
java_exception = convert_py4j_exception(e)
break
else:
raise
Expand Down Expand Up @@ -197,14 +193,9 @@ def convert_py4j_exception(e: Py4JJavaError) -> JavaException:
"""
Convert Py4J exception to JavaException.
"""
def extract_java_stack_trace(java_stack_trace):
return '\n\t at '.join(map(lambda x: x.toString(), java_stack_trace))

s = e.java_exception.toString()
cause = e.java_exception.getCause()
stack_trace = extract_java_stack_trace(e.java_exception.getStackTrace())
while cause is not None:
stack_trace += '\nCaused by: %s: %s' % (cause.getClass().getName(), cause.getMessage())
stack_trace += "\n\t at " + extract_java_stack_trace(cause.getStackTrace())
cause = cause.getCause()
return JavaException(s.split(': ', 1)[1], stack_trace)
for exception in exception_mapping.keys():
if s.startswith(exception):
return exception_mapping[exception](str(e).split(': ', 1)[1])
else:
return JavaException(str(e).split(': ', 1)[1])