This is an automated email from the ASF dual-hosted git repository.

sijie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new 29104ef  improve error message handling (#2435)
29104ef is described below

commit 29104efedccf2efd5a9f4cec1b1cab9c8a621d48
Author: Boyang Jerry Peng <[email protected]>
AuthorDate: Fri Aug 24 11:34:21 2018 -0700

    improve error message handling (#2435)
    
    ### Motivation
    
    Improve error message handling in presto pulsar connector
---
 .../org/apache/pulsar/sql/presto/PulsarConnectorUtils.java |  4 +++-
 .../java/org/apache/pulsar/sql/presto/PulsarMetadata.java  | 14 ++++++++++----
 .../org/apache/pulsar/sql/presto/PulsarSplitManager.java   | 10 ++++++----
 3 files changed, 19 insertions(+), 9 deletions(-)

diff --git 
a/pulsar-sql/presto-pulsar/src/main/java/org/apache/pulsar/sql/presto/PulsarConnectorUtils.java
 
b/pulsar-sql/presto-pulsar/src/main/java/org/apache/pulsar/sql/presto/PulsarConnectorUtils.java
index 012a554..e537574 100644
--- 
a/pulsar-sql/presto-pulsar/src/main/java/org/apache/pulsar/sql/presto/PulsarConnectorUtils.java
+++ 
b/pulsar-sql/presto-pulsar/src/main/java/org/apache/pulsar/sql/presto/PulsarConnectorUtils.java
@@ -19,6 +19,7 @@
 package org.apache.pulsar.sql.presto;
 
 import org.apache.avro.Schema;
+import org.apache.commons.lang3.exception.ExceptionUtils;
 import org.apache.pulsar.client.admin.PulsarAdmin;
 import org.apache.pulsar.client.admin.PulsarAdminException;
 import org.apache.pulsar.common.naming.TopicName;
@@ -34,7 +35,8 @@ public class PulsarConnectorUtils {
         try {
             return 
pulsarAdmin.topics().getPartitionedTopicMetadata(topicName.toString()).partitions
 > 0;
         } catch (PulsarAdminException e) {
-            throw new RuntimeException(e);
+            throw new RuntimeException("Failed to determine if topic " + 
topicName + " is partitioned: "
+                    + ExceptionUtils.getRootCause(e).getLocalizedMessage(), e);
         }
     }
 }
diff --git 
a/pulsar-sql/presto-pulsar/src/main/java/org/apache/pulsar/sql/presto/PulsarMetadata.java
 
b/pulsar-sql/presto-pulsar/src/main/java/org/apache/pulsar/sql/presto/PulsarMetadata.java
index 20a56bb..6e30ea5 100644
--- 
a/pulsar-sql/presto-pulsar/src/main/java/org/apache/pulsar/sql/presto/PulsarMetadata.java
+++ 
b/pulsar-sql/presto-pulsar/src/main/java/org/apache/pulsar/sql/presto/PulsarMetadata.java
@@ -52,6 +52,7 @@ import org.apache.avro.LogicalTypes;
 import org.apache.avro.Schema;
 import org.apache.avro.SchemaParseException;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.exception.ExceptionUtils;
 import org.apache.pulsar.client.admin.PulsarAdmin;
 import org.apache.pulsar.client.admin.PulsarAdminException;
 import org.apache.pulsar.client.api.PulsarClientException;
@@ -103,7 +104,8 @@ public class PulsarMetadata implements ConnectorMetadata {
                 
prestoSchemas.addAll(pulsarAdmin.namespaces().getNamespaces(tenant));
             }
         } catch (PulsarAdminException e) {
-            throw new RuntimeException("Failed to get schemas from pulsar", e);
+            throw new RuntimeException("Failed to get schemas from pulsar: "
+                    + ExceptionUtils.getRootCause(e).getLocalizedMessage(), e);
         }
         return prestoSchemas;
     }
@@ -150,7 +152,8 @@ public class PulsarMetadata implements ConnectorMetadata {
                     log.warn("Schema " + schemaNameOrNull + " does not exsit");
                     return builder.build();
                 }
-                throw new RuntimeException("Failed to get tables/topics in " + 
schemaNameOrNull, e);
+                throw new RuntimeException("Failed to get tables/topics in " + 
schemaNameOrNull + ": "
+                        + 
ExceptionUtils.getRootCause(e).getLocalizedMessage(), e);
             }
             if (pulsarTopicList != null) {
                 pulsarTopicList.forEach(topic -> builder.add(
@@ -247,7 +250,8 @@ public class PulsarMetadata implements ConnectorMetadata {
             if (e.getStatusCode() == 404) {
                 throw new PrestoException(NOT_FOUND, "Schema " + 
schemaTableName.getSchemaName() + " does not exist");
             }
-            throw new RuntimeException(e);
+            throw new RuntimeException("Failed to get topics in schema " + 
schemaTableName.getSchemaName()
+                    + ": " + 
ExceptionUtils.getRootCause(e).getLocalizedMessage(), e);
         }
 
         if (!topics.contains(topicName.toString())) {
@@ -265,7 +269,9 @@ public class PulsarMetadata implements ConnectorMetadata {
             if (e.getStatusCode() == 404) {
                 throw new PrestoException(NOT_SUPPORTED, "Topic " + 
topicName.toString() + " does not have a schema");
             }
-            throw new RuntimeException(e);
+            throw new RuntimeException("Failed to get schema information for 
topic "
+                    + String.format("%s/%s", schemaTableName.getSchemaName(), 
schemaTableName.getTableName())
+                    + ": " + 
ExceptionUtils.getRootCause(e).getLocalizedMessage(), e);
         }
 
         String schemaJson = new String(schemaInfo.getSchema());
diff --git 
a/pulsar-sql/presto-pulsar/src/main/java/org/apache/pulsar/sql/presto/PulsarSplitManager.java
 
b/pulsar-sql/presto-pulsar/src/main/java/org/apache/pulsar/sql/presto/PulsarSplitManager.java
index 488609d..45a2e4f 100644
--- 
a/pulsar-sql/presto-pulsar/src/main/java/org/apache/pulsar/sql/presto/PulsarSplitManager.java
+++ 
b/pulsar-sql/presto-pulsar/src/main/java/org/apache/pulsar/sql/presto/PulsarSplitManager.java
@@ -39,6 +39,7 @@ import org.apache.bookkeeper.mledger.ManagedLedgerFactory;
 import org.apache.bookkeeper.mledger.ReadOnlyCursor;
 import org.apache.bookkeeper.mledger.impl.ManagedLedgerFactoryImpl;
 import org.apache.bookkeeper.mledger.impl.PositionImpl;
+import org.apache.commons.lang3.exception.ExceptionUtils;
 import org.apache.pulsar.client.admin.PulsarAdmin;
 import org.apache.pulsar.client.admin.PulsarAdminException;
 import org.apache.pulsar.client.api.PulsarClientException;
@@ -100,8 +101,9 @@ public class PulsarSplitManager implements 
ConnectorSplitManager {
             schemaInfo = this.pulsarAdmin.schemas().getSchemaInfo(
                     String.format("%s/%s", tableHandle.getSchemaName(), 
tableHandle.getTableName()));
         } catch (PulsarAdminException e) {
-            log.error(e);
-            throw new RuntimeException(e);
+            throw new RuntimeException("Failed to get schema for topic "
+                    + String.format("%s/%s", tableHandle.getSchemaName(), 
tableHandle.getTableName())
+                    + ": " + 
ExceptionUtils.getRootCause(e).getLocalizedMessage(), e);
         }
 
         Collection<PulsarSplit> splits;
@@ -136,8 +138,8 @@ public class PulsarSplitManager implements 
ConnectorSplitManager {
         try {
             numPartitions = 
(this.pulsarAdmin.topics().getPartitionedTopicMetadata(topicName.toString())).partitions;
         } catch (PulsarAdminException e) {
-            log.error(e);
-            throw new RuntimeException(e);
+            throw new RuntimeException("Failed to get metadata for partitioned 
topic "
+                    + topicName + ": " + 
ExceptionUtils.getRootCause(e).getLocalizedMessage(),e);
         }
 
         int actualNumSplits = Math.max(numPartitions, numSplits);

Reply via email to