diqiu50 commented on code in PR #9446:
URL: https://github.com/apache/gravitino/pull/9446#discussion_r2606771807
##########
catalogs/hive-metastore-common/src/main/java/org/apache/gravitino/hive/client/HiveExceptionConverter.java:
##########
@@ -89,6 +103,134 @@ private HiveExceptionConverter() {}
* @return A Gravitino exception
*/
public static RuntimeException toGravitinoException(Exception e,
ExceptionTarget target) {
- return null;
+ Throwable cause = unwrapException(e);
+ return convertException(cause, target);
+ }
+
+ /**
+ * Unwraps nested exceptions, especially InvocationTargetException from
reflection calls.
+ *
+ * @param e The exception to unwrap
+ * @return The unwrapped exception
+ */
+ private static Throwable unwrapException(Exception e) {
+ Throwable cause = e;
+ if (e instanceof InvocationTargetException) {
+ InvocationTargetException ite = (InvocationTargetException) e;
+ cause = ite.getTargetException();
+ if (cause == null) {
+ cause = e;
+ }
+ }
+ return cause;
+ }
+
+ /**
+ * Converts the exception to the appropriate Gravitino exception based on
its type.
+ *
+ * @param cause The exception cause
+ * @param target The target Hive object of the operation
+ * @return A Gravitino exception
+ */
+ private static RuntimeException convertException(Throwable cause,
ExceptionTarget target) {
+ if (cause instanceof RuntimeException && cause.getCause() instanceof
Exception) {
+ return toGravitinoException((Exception) cause.getCause(), target);
+ }
+
+ String message = cause.getMessage();
+ String lowerMessage = message != null ? message.toLowerCase(Locale.ROOT) :
"";
+ String exceptionClassName = cause.getClass().getName();
+
+ if (exceptionClassName.contains("AlreadyExistsException")) {
+ return toAlreadyExistsException(cause, target, message);
+ }
+ if (exceptionClassName.contains("NoSuchObjectException")
Review Comment:
fixed
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]