sijie closed pull request #2435: improve error message handling
URL: https://github.com/apache/incubator-pulsar/pull/2435
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
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 012a5545a7..e537574194 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 static boolean isPartitionedTopic(TopicName topicName,
PulsarAdmin pulsar
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 c04156eca7..d65db6ad88 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
@@ -49,6 +49,7 @@
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;
@@ -98,7 +99,8 @@ public PulsarMetadata(PulsarConnectorId connectorId,
PulsarConnectorConfig pulsa
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;
}
@@ -144,7 +146,8 @@ public ConnectorTableMetadata
getTableMetadata(ConnectorSession session, Connect
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(
@@ -241,7 +244,8 @@ private ConnectorTableMetadata
getTableMetadata(SchemaTableName schemaTableName,
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())) {
@@ -259,7 +263,9 @@ private ConnectorTableMetadata
getTableMetadata(SchemaTableName schemaTableName,
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 721b8e6d88..9a94e3037a 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
@@ -32,6 +32,7 @@
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;
@@ -88,8 +89,9 @@ public ConnectorSplitSource
getSplits(ConnectorTransactionHandle transactionHand
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;
@@ -124,8 +126,8 @@ ManagedLedgerFactory getManagedLedgerFactory() throws
Exception {
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);
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services