You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@avro.apache.org by GitBox <gi...@apache.org> on 2020/08/07 13:52:30 UTC

[GitHub] [avro] RyanSkraba commented on a change in pull request #933: AVRO-2892: Isolate Errors to Simplify Import Graph

RyanSkraba commented on a change in pull request #933:
URL: https://github.com/apache/avro/pull/933#discussion_r467045104



##########
File path: lang/py/avro/schema.py
##########
@@ -1120,22 +1100,25 @@ def make_avsc_object(json_data, names=None, validate_enum_symbols=True):
     # not for us!
     else:
         fail_msg = "Could not make an Avro Schema object from %s." % json_data
-        raise SchemaParseException(fail_msg)
+        raise avro.errors.SchemaParseException(fail_msg)
 
 # TODO(hammer): make method for reading from a file?
 
 
-def parse(json_string, validate_enum_symbols=True):
+def parse(json_string, validate_enum_symbols=True, register_codec=None):
     """Constructs the Schema from the JSON text.
 
+    @arg json_string: The json string of the schema to parse
     @arg validate_enum_symbols: If False, will allow enum symbols that are not valid Avro names.
+    @arg register_codec: If a string, registers a Python codec by that name.

Review comment:
       Is including register_codec intentional for this PR?

##########
File path: lang/py/avro/errors.py
##########
@@ -0,0 +1,79 @@
+#!/usr/bin/env python
+
+##
+# 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
+#
+# https://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.
+
+import json
+
+
+class AvroException(Exception):
+    """The base class for exceptions in avro."""
+
+
+class SchemaParseException(AvroException):
+    """Raised when a schema failed to parse."""
+
+
+class InvalidName(SchemaParseException):
+    """User attempted to parse a schema with an invalid name."""
+
+
+class AvroWarning(UserWarning):
+    """Base class for warnings."""
+
+
+class IgnoredLogicalType(AvroWarning):
+    """Warnings for unknown or invalid logical types."""
+
+
+class AvroTypeException(AvroException):
+    """Raised when datum is not an example of schema."""
+    def __init__(self, expected_schema, datum):
+        pretty_expected = json.dumps(json.loads(str(expected_schema)), indent=2)
+        fail_msg = "The datum {} is not an example of the schema {}".format(datum, pretty_expected)
+        super(AvroTypeException, self).__init__(fail_msg)
+
+
+class SchemaResolutionException(AvroException):
+    def __init__(self, fail_msg, writers_schema=None, readers_schema=None):
+        pretty_writers = json.dumps(json.loads(str(writers_schema)), indent=2)
+        pretty_readers = json.dumps(json.loads(str(readers_schema)), indent=2)
+        if writers_schema:
+            fail_msg += "\nWriter's Schema: {}".format(pretty_writers)
+        if readers_schema:
+            fail_msg += "\nReader's Schema: {}".format(pretty_readers)
+        super(AvroException, self).__init__(fail_msg)
+
+
+class DataFileException(AvroException):
+    """Raised when there's a problem reading or writing file object containers."""
+
+
+class AvroRemoteException(AvroException):
+    """Raised when an error message is sent by an Avro requestor or responder."""
+
+
+class ConnectionClosedException(AvroException):
+    """Raised when attempting IPC on a closed connection."""
+
+
+class ProtocolParseException(AvroException):
+    """Raised when a protocol failed to parse."""
+
+
+class AvroError(RuntimeError, AvroException):

Review comment:
       The doc for this is correct, it's only used for communicating with the user when a CLI tool is incorrectly parameterized.  How about a more specific name `AvroToolError` or `AvroParameterError` or `AvroUsageError`?




----------------------------------------------------------------
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:
users@infra.apache.org