yanivru commented on a change in pull request #1597:
URL: https://github.com/apache/avro/pull/1597#discussion_r839013329



##########
File path: lang/csharp/src/apache/main/Schema/EnumSchema.cs
##########
@@ -98,20 +128,50 @@ internal static EnumSchema NewInstance(JToken jtok, 
PropertyMap props, SchemaNam
         /// <param name="names">list of named schema already read</param>
         /// <param name="doc">documentation for this named schema</param>
         /// <param name="defaultSymbol">default symbol</param>
+        /// <param name="shouldThrowParseException">If true, will throw <see 
cref="SchemaParseException"/> in case of an error. If false, will throw <see 
cref="AvroException"/> in case of an error.</param>
         private EnumSchema(SchemaName name, IList<SchemaName> aliases, 
List<string> symbols,
                             IDictionary<String, int> symbolMap, PropertyMap 
props, SchemaNames names,
-                            string doc, string defaultSymbol)
+                            string doc, string defaultSymbol, bool 
shouldThrowParseException = true)
                             : base(Type.Enumeration, name, aliases, props, 
names, doc)
         {
-            if (null == name.Name) throw new SchemaParseException("name cannot 
be null for enum schema.");
+            if (null == name.Name) throw CreateException("name cannot be null 
for enum schema.", shouldThrowParseException);
             this.Symbols = symbols;
             this.symbolMap = symbolMap;
 
             if (null != defaultSymbol && !symbolMap.ContainsKey(defaultSymbol))
-                throw new SchemaParseException($"Default symbol: 
{defaultSymbol} not found in symbols");
+                throw CreateException($"Default symbol: {defaultSymbol} not 
found in symbols", shouldThrowParseException);
             Default = defaultSymbol;
         }
 
+        private Exception CreateException(string message, bool 
shouldCreateParseException)
+        {
+            return shouldCreateParseException ? new 
SchemaParseException(message) : new AvroException(message);
+        }
+
+        /// <summary>
+        /// Creates symbols map from specified list of symbols.
+        /// Symbol map contains the names of the symbols and their index.
+        /// </summary>
+        /// <param name="symbols">List of symbols</param>
+        /// <returns>Symbol map</returns>
+        /// <exception cref="AvroException">Is thrown if the symbols list 
contains duplicate symbols.</exception>
+        private static IDictionary<string, int> 
CreateSymbolsMap(IEnumerable<string> symbols)
+        {
+            IDictionary<string, int> symbolMap = new Dictionary<string, int>();
+            int i = 0;
+            foreach (var symbol in symbols)
+            {
+                if (symbolMap.ContainsKey(symbol))

Review comment:
       ArgumentException or AvroException? The convention everywhere in the 
code is to throw AvroException even in cases that ArgumentException seems more 
appropriate.




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to