-
Notifications
You must be signed in to change notification settings - Fork 28.7k
[SPARK-53126][SQL][CONNECT] Refactor SparkErrorUtils#stackTraceToString
to handle null
input and use it to replace ExceptionUtils#getStackTrace
#51844
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
Conversation
throwable.printStackTrace(writer) | ||
writer.flush() | ||
} | ||
new String(out.toByteArray, UTF_8) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation of ExceptionUtils#getStackTrace
is as follows:
/**
* Gets the stack trace from a Throwable as a String, including suppressed and cause exceptions.
*
* <p>
* The result of this method vary by JDK version as this method
* uses {@link Throwable#printStackTrace(java.io.PrintWriter)}.
* </p>
*
* @param throwable the {@link Throwable} to be examined, may be null
* @return the stack trace as generated by the exception's
* {@code printStackTrace(PrintWriter)} method, or an empty String if {@code null} input
*/
public static String getStackTrace(final Throwable throwable) {
if (throwable == null) {
return StringUtils.EMPTY;
}
final StringWriter sw = new StringWriter();
throwable.printStackTrace(new PrintWriter(sw, true));
return sw.toString();
}
@dongjoon-hyun Do you agree to replace them with the refactored stackTraceToString
?
The difference, as I see it, lies in the encoding—stackTraceToString
always uses UTF-8
, while getStackTrace
uses the default encoding.
If this is an issue, I can add a new getStackTrace
method without modifying stackTraceToString
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for this PR, @LuciferYang . Thank you.
SparkErrorUtils#stackTraceToString
to handle null
input and use it to replace ExceptionUtils#getStackTrace
SparkErrorUtils#stackTraceToString
to handle null
input and use it to replace ExceptionUtils#getStackTrace
Thank you @dongjoon-hyun ~ |
All test passed |
Merged into master for Apache Spark 4.1.0. Thanks @dongjoon-hyun |
What changes were proposed in this pull request?
This PR refactor
SparkErrorUtils#stackTraceToString
to handlenull
input and use it to replaceExceptionUtils#getStackTrace
.Why are the changes needed?
To improve Spark's error utility functions.
Does this PR introduce any user-facing change?
No behavior change.
How was this patch tested?
Was this patch authored or co-authored using generative AI tooling?
No.