changeset 154:0520cc00c0cc

Better error reporting for loading translations; avoided an infinite loop.
author Diggory Hardy <diggory.hardy@gmail.com>
date Sat, 18 Apr 2009 12:02:33 +0200
parents 2934fcacbb97
children 4e8819b65882
files mde/content/Translation.d mde/file/deserialize.d
diffstat 2 files changed, 16 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/mde/content/Translation.d	Fri Apr 10 18:09:55 2009 +0200
+++ b/mde/content/Translation.d	Sat Apr 18 12:02:33 2009 +0200
@@ -78,7 +78,6 @@
         char[][] files = [loadedL10n];	// initial locale plus dependencies
         size_t read = 0;	// index in files of next file to read
         while (read < files.length) {
-            logger.trace ("reading file {}", files[read]);
             try {
                 MTTagReader reader = dataDir.makeMTTagReader ("L10n/"~files[read], PRIORITY.HIGH_LOW);
                 bool isSecTag;
@@ -110,20 +109,26 @@
                             // If the tag already exists, don't replace it
                             if (sym in entries) continue;
                             
-                            Entry entry = deserialize!(Entry) (reader.tagData);
-                            if (entry.name is null) {   // This tag is invalid; ignore it
-                                logger.error ("In L10n/{}.mtt: tag {} has no name", files[read], sym);
-                                continue;
-                            }
-                            entries[sym] = entry;
+			    try {
+			      Entry entry = deserialize!(Entry) (reader.tagData);
+			      if (entry.name is null)	// This tag is invalid; ignore it
+                                throw new ContentException ("Tag has no name");
+			      entries[sym] = entry;
+			    } catch (Exception e) {
+			      logger.error ("Exception reading L10n/{}.mtt:", files[read]);
+			      logger.error ("While parsing tag {}", sym);
+			      logger.error (e.msg);
+			      continue;
+			    }
                         }
                     }
                 } while (reader.readTag (isSecTag))
-                ++read;
             } catch (Exception e) {
-                logger.error ("Exception loading translation: {}", e.msg);
+	      logger.error ("Exception reading L10n/{}.mtt:", files[read]);
+	      logger.error (e.msg);
             }
-        }
+	    ++read;	// continue to next file regardless of whether this file was read successfully
+	}
     }
     
     /+ Getters for entries... not wanted now.
--- a/mde/file/deserialize.d	Fri Apr 10 18:09:55 2009 +0200
+++ b/mde/file/deserialize.d	Sat Apr 18 12:02:33 2009 +0200
@@ -306,7 +306,7 @@
             ++i;
         }
         if (i >= pair.length)
-            throw new ParseException ("Invalid struct: encountered { ... KEY} (missing :DATA)");
+            throw new ParseException ("Invalid KEY:DATA pair within struct: "~pair);
         
         size_t k = deserialize!(size_t) (pair[0..i]);
         // Note: could check no entry was already stored in temp.