Throw special exception if a time can not be parsed.
[Sone.git] / src / main / java / net / pterodactylus / sone / core / SoneParser.java
index ab05b97..1fe4794 100644 (file)
@@ -147,13 +147,13 @@ public class SoneParser {
                                String fieldValue = fieldXml.getValue("field-value", "");
                                if (fieldName == null) {
                                        logger.log(Level.WARNING, String.format("Downloaded profile field for Sone %s with missing data! Name: %s, Value: %s", sone, fieldName, fieldValue));
-                                       return null;
+                                       throw new MalformedXml();
                                }
                                try {
                                        profile.setField(profile.addField(fieldName), fieldValue);
                                } catch (IllegalArgumentException iae1) {
                                        logger.log(Level.WARNING, String.format("Duplicate field: %s", fieldName), iae1);
-                                       return null;
+                                       throw new DuplicateField();
                                }
                        }
                }
@@ -173,7 +173,7 @@ public class SoneParser {
                                if ((postId == null) || (postTime == null) || (postText == null)) {
                                        /* TODO - mark Sone as bad. */
                                        logger.log(Level.WARNING, String.format("Downloaded post for Sone %s with missing data! ID: %s, Time: %s, Text: %s", sone, postId, postTime, postText));
-                                       return null;
+                                       throw new MalformedXml();
                                }
                                try {
                                        PostBuilder postBuilder = sone.newPostBuilder();
@@ -186,7 +186,7 @@ public class SoneParser {
                                } catch (NumberFormatException nfe1) {
                                        /* TODO - mark Sone as bad. */
                                        logger.log(Level.WARNING, String.format("Downloaded post for Sone %s with invalid time: %s", sone, postTime));
-                                       return null;
+                                       throw new MalformedTime();
                                }
                        }
                }
@@ -355,4 +355,12 @@ public class SoneParser {
        public static class MalformedXml extends RuntimeException {
 
        }
+
+        public static class DuplicateField extends RuntimeException {
+
+       }
+
+       public static class MalformedTime extends RuntimeException {
+
+       }
 }