[tomboy] Improve error reportiing on note parsing errors



commit 8f4cdb289c6154d278486c1c70f42d5163807ea9
Author: Guido Günther <agx sigxcpu org>
Date:   Mon Nov 4 18:41:28 2013 +0100

    Improve error reportiing on note parsing errors
    
    Print the uuid, key and value that failed to parse. Otherwise one just
    sees:
    
    [ERROR 18:34:52.808] Synchronization failed with the following exception: Cannot cast from source type to 
destination type.
      at Tomboy.WebSync.Api.NoteInfo.ParseJson (Hyena.Json.JsonObject jsonObj) [0x00000] in <filename 
unknown>:0
      at Tomboy.WebSync.Api.UserInfo.ParseJsonNoteArray (Hyena.Json.JsonArray jsonArray) [0x00000] in 
<filename unknown>:0
      at Tomboy.WebSync.Api.UserInfo.ParseJsonNotes (System.String jsonString, System.Nullable`1& 
latestSyncRevision) [0x00000] in <filename unknown>:0
      at Tomboy.WebSync.Api.UserInfo.GetNotes (Boolean includeContent, Int32 sinceRevision, 
System.Nullable`1& latestSyncRevision) [0x00000] in <filename unknown>:0
      at Tomboy.WebSync.WebSyncServer.GetNoteUpdatesSince (Int32 revision) [0x00000] in <filename unknown>:0
      at Tomboy.Sync.SyncManager.SynchronizationThread () [0x00000] in <filename unknown>:0
    
    This makes debugging parsing errors send back from the server much
    simpler.
    
    Signed-off-by: Jared Jennings <jared jaredjennings org>

 Tomboy/Addins/WebSyncService/Api/NoteInfo.cs |   84 +++++++++++++++----------
 1 files changed, 50 insertions(+), 34 deletions(-)
---
diff --git a/Tomboy/Addins/WebSyncService/Api/NoteInfo.cs b/Tomboy/Addins/WebSyncService/Api/NoteInfo.cs
index 5546991..4a12e94 100644
--- a/Tomboy/Addins/WebSyncService/Api/NoteInfo.cs
+++ b/Tomboy/Addins/WebSyncService/Api/NoteInfo.cs
@@ -53,44 +53,60 @@ namespace Tomboy.WebSync.Api
                        note.Guid = (string) jsonObj ["guid"];
 
                        // TODO: Decide how much is required
-                       object val;
-
-                       if (jsonObj.TryGetValue (TitleElementName, out val))
-                               note.Title = (string) val;
-                       if (jsonObj.TryGetValue (NoteContentElementName, out val))
-                               note.NoteContent = (string) val;
-                       if (jsonObj.TryGetValue (NoteContentVersionElementName, out val))
-                               note.NoteContentVersion = (double) val;
-                       
-                       if (jsonObj.TryGetValue (LastChangeDateElementName, out val))
-                               note.LastChangeDate = DateTime.Parse ((string) val);
-                       if (jsonObj.TryGetValue (LastMetadataChangeDateElementName, out val))
-                               note.LastMetadataChangeDate = DateTime.Parse ((string) val);
-                       if (jsonObj.TryGetValue (CreateDateElementName, out val))
-                               note.CreateDate = DateTime.Parse ((string) val);
-                       
-                       if (jsonObj.TryGetValue (LastSyncRevisionElementName, out val))
-                               note.LastSyncRevision = (int) val;
-                       if (jsonObj.TryGetValue (OpenOnStartupElementName, out val))
-                               note.OpenOnStartup = (bool) val;
-                       if (jsonObj.TryGetValue (PinnedElementName, out val))
-                               note.Pinned = (bool) val;
-                       
-                       if (jsonObj.TryGetValue (TagsElementName, out val)) {
-                               Hyena.Json.JsonArray tagsJsonArray =
-                                       (Hyena.Json.JsonArray) val;
-                               note.Tags = new List<string> (tagsJsonArray.Count);
-                               foreach (string tag in tagsJsonArray)
-                                       note.Tags.Add (tag);
+                       object val = 0;
+                       string key = "<unknown>";
+                       try {
+                               key = TitleElementName;
+                               if (jsonObj.TryGetValue (key, out val))
+                                       note.Title = (string) val;
+                               key = NoteContentElementName;
+                               if (jsonObj.TryGetValue (key, out val))
+                                       note.NoteContent = (string) val;
+                               key = NoteContentVersionElementName;
+                               if (jsonObj.TryGetValue (key, out val))
+                                       note.NoteContentVersion = (double) val;
+
+                               key = LastChangeDateElementName;
+                               if (jsonObj.TryGetValue (key, out val))
+                                       note.LastChangeDate = DateTime.Parse ((string) val);
+                               key = LastMetadataChangeDateElementName;
+                               if (jsonObj.TryGetValue (key, out val))
+                                       note.LastMetadataChangeDate = DateTime.Parse ((string) val);
+                               key = CreateDateElementName;
+                               if (jsonObj.TryGetValue (key, out val))
+                                       note.CreateDate = DateTime.Parse ((string) val);
+
+                               key = LastSyncRevisionElementName;
+                               if (jsonObj.TryGetValue (key, out val))
+                                       note.LastSyncRevision = (int) val;
+                               key = OpenOnStartupElementName;
+                               if (jsonObj.TryGetValue (key, out val))
+                                       note.OpenOnStartup = (bool) val;
+                               key = PinnedElementName;
+                               if (jsonObj.TryGetValue (key, out val))
+                                       note.Pinned = (bool) val;
+
+                               key = TagsElementName;
+                               if (jsonObj.TryGetValue (key, out val)) {
+                                       Hyena.Json.JsonArray tagsJsonArray =
+                                               (Hyena.Json.JsonArray) val;
+                                       note.Tags = new List<string> (tagsJsonArray.Count);
+                                       foreach (string tag in tagsJsonArray)
+                                               note.Tags.Add (tag);
+                               }
+
+                               key = ResourceReferenceElementName;
+                               if (jsonObj.TryGetValue (key, out val))
+                                       note.ResourceReference =
+                                               ResourceReference.ParseJson ((Hyena.Json.JsonObject) val);
+                       } catch (InvalidCastException e) {
+                               Logger.Error("Note '{0}': Key '{1}', value  '{2}' failed to parse due to 
invalid type", note.Guid, key, val);
+                               throw e;
                        }
 
-                       if (jsonObj.TryGetValue (ResourceReferenceElementName, out val))
-                               note.ResourceReference =
-                                       ResourceReference.ParseJson ((Hyena.Json.JsonObject) val);
-
                        return note;
                }
-               
+
                #endregion
 
                #region Public Methods


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]