itholic commented on code in PR #39693:
URL: https://github.com/apache/spark/pull/39693#discussion_r1083316715


##########
python/pyspark/errors/exceptions.py:
##########
@@ -288,7 +291,57 @@ class UnknownException(CapturedException):
 
 class SparkUpgradeException(CapturedException):
     """
-    Exception thrown because of Spark upgrade
+    Exception thrown because of Spark upgrade.
+    """
+
+
+class SparkConnectException(PySparkException):
+    """
+    Exception thrown from Spark Connect.
+    """
+
+
+class SparkConnectGrpcException(SparkConnectException):
+    """
+    Base class to handle the errors from GRPC.
+    """
+
+    def __init__(
+        self,
+        message: Optional[str] = None,
+        error_class: Optional[str] = None,
+        message_parameters: Optional[Dict[str, str]] = None,
+        plan: Optional[str] = None,
+        reason: Optional[str] = None,

Review Comment:
   `SparkConnectGrpcException` is a specialized `SparkConnectException` to 
handle errors that occur in GRPC.
   
   And `plan` and `reason` come from `grpc.RpcError`, so I moved them from 
`SparkConnectException`.



##########
python/pyspark/sql/connect/client.py:
##########
@@ -628,21 +612,33 @@ def _handle_error(self, rpc_error: grpc.RpcError) -> 
NoReturn:
                 if d.Is(error_details_pb2.ErrorInfo.DESCRIPTOR):
                     info = error_details_pb2.ErrorInfo()
                     d.Unpack(info)
-                    if info.reason == "org.apache.spark.sql.AnalysisException":
+                    reason = info.reason
+                    if reason == "org.apache.spark.sql.AnalysisException":
                         raise SparkConnectAnalysisException(
-                            info.reason, info.metadata["message"], 
info.metadata["plan"]

Review Comment:
   I don't use `reason` from `SparkConnectAnalysisException` and other 
specified Exceptions (e.g. `SparkConnectParseException`, 
`SparkConnectTempTableAlreadyExistsException`), since I believe the name of 
exception sounds self-explanatory.



-- 
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: reviews-unsubscr...@spark.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to