[ 
https://issues.apache.org/jira/browse/HIVE-25055?focusedWorklogId=604936&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-604936
 ]

ASF GitHub Bot logged work on HIVE-25055:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 02/Jun/21 04:14
            Start Date: 02/Jun/21 04:14
    Worklog Time Spent: 10m 
      Work Description: dengzhhu653 commented on a change in pull request #2218:
URL: https://github.com/apache/hive/pull/2218#discussion_r643639099



##########
File path: 
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ExceptionHandler.java
##########
@@ -0,0 +1,149 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hive.metastore;
+
+import org.apache.hadoop.hive.metastore.api.MetaException;
+import org.apache.hadoop.hive.metastore.api.NoSuchObjectException;
+import org.apache.hadoop.hive.metastore.utils.JavaUtils;
+import org.apache.thrift.TException;
+
+import static java.util.Objects.requireNonNull;
+
+public final class ExceptionHandler {
+  private final Exception e;
+
+  private ExceptionHandler(Exception e) {
+    this.e = e;
+  }
+
+  public static ExceptionHandler handleException(Exception e) {
+    requireNonNull(e, "Exception e is null");
+    return new ExceptionHandler(e);
+  }
+
+  /**
+   * Throws if the input e is the instance of the class clz
+   */
+  public <T extends Exception> ExceptionHandler
+      throwIfInstance(Class<T> t) throws T {
+    if (t.isInstance(e)) {
+      throw t.cast(e);
+    }
+    return this;
+  }
+
+  /**
+   * Throws if the input e is the instance of the class clzt or  class clze in 
order
+   */
+  public <T extends Exception, E extends Exception> ExceptionHandler
+      throwIfInstance(Class<T> t, Class<E> e) throws T, E {
+    throwIfInstance(t);
+    throwIfInstance(e);
+    return this;
+  }
+
+  /**
+   * Throws if the input e is the instance of the class clzt or  clze or clzc 
in order
+   */
+  public <T extends Exception, E extends Exception, C extends Exception> 
ExceptionHandler
+      throwIfInstance(Class<T> t, Class<E> e, Class<C> c) throws T, E, C {
+    throwIfInstance(t);
+    throwIfInstance(e);
+    throwIfInstance(c);
+    return this;
+  }
+
+  /**
+   * Converts the input e if it is the instance of class from to the instance 
of class to and throws
+   */
+  public <T extends Exception, D extends TException> ExceptionHandler
+      convertIfInstance(Class<T> from, Class<D> to) throws D {
+    D targetException = null;
+    if (from.isInstance(e)) {
+      try {
+        targetException = JavaUtils.newInstance(to, new Class[]{String.class}, 
new Object[]{e.getMessage()});
+      } catch (Exception ex) {
+        // this should not happen
+        throw new RuntimeException(ex);
+      }
+    }
+    if (targetException != null) {
+      throw targetException;
+    }
+
+    return this;
+  }
+
+  /**
+   * Converts the input e if it is the instance of classes to MetaException 
with the given message
+   */
+  public ExceptionHandler convertToMetaExIfInstance(String message, 
Class<?>... classes)
+      throws MetaException {
+    if (classes != null && classes.length > 0) {
+      for (Class<?> clz : classes) {
+        if (clz.isInstance(e)) {
+          // throw the exception if matches
+          throw new MetaException(message);
+        }
+      }
+    }
+    return this;
+  }
+
+  public static TException rethrowException(Exception e) throws TException {

Review comment:
       Done




-- 
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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 604936)
    Time Spent: 2h 20m  (was: 2h 10m)

> Improve the exception handling in HMSHandler
> --------------------------------------------
>
>                 Key: HIVE-25055
>                 URL: https://issues.apache.org/jira/browse/HIVE-25055
>             Project: Hive
>          Issue Type: Improvement
>          Components: Standalone Metastore
>            Reporter: Zhihua Deng
>            Assignee: Zhihua Deng
>            Priority: Minor
>              Labels: pull-request-available
>          Time Spent: 2h 20m
>  Remaining Estimate: 0h
>




--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to