[geary/wip/email-flag-refinement: 3/6] Explicity throw an error when requirements aren't met for setting flags



commit fa48f989f7cbfd52e3cc82ec297347562e228e72
Author: Michael Gratton <mike vee net>
Date:   Wed Feb 13 18:44:01 2019 +1100

    Explicity throw an error when requirements aren't met for setting flags
    
    It's probably a programmign error if an error is thrown, but bugs will
    never be caught if they errors aren't thrown.

 src/engine/imap-db/imap-db-folder.vala | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)
---
diff --git a/src/engine/imap-db/imap-db-folder.vala b/src/engine/imap-db/imap-db-folder.vala
index 528df3ff..fbd51020 100644
--- a/src/engine/imap-db/imap-db-folder.vala
+++ b/src/engine/imap-db/imap-db-folder.vala
@@ -1711,15 +1711,24 @@ private class Geary.ImapDB.Folder : BaseObject, Geary.ReferenceSemantics {
             "UPDATE MessageTable SET flags=?, fields = fields | ? WHERE id=?");
         
         foreach (ImapDB.EmailIdentifier id in map.keys) {
-            LocationIdentifier? location = do_get_location_for_id(cx, id, ListFlags.NONE,
-                cancellable);
-            if (location == null)
-                continue;
-            
-            Geary.Imap.MessageFlags flags = ((Geary.Imap.EmailFlags) map.get(id)).message_flags;
-            
+            LocationIdentifier? location = do_get_location_for_id(
+                cx, id, ListFlags.NONE, cancellable
+            );
+            if (location == null) {
+                throw new EngineError.NOT_FOUND(
+                    "Email not found: %s", id.to_string()
+                );
+            }
+
+            Geary.Imap.EmailFlags? flags = map.get(id) as Geary.Imap.EmailFlags;
+            if (flags == null) {
+                throw new EngineError.BAD_PARAMETERS(
+                    "Email with Geary.Imap.EmailFlags required"
+                );
+            }
+
             update_stmt.reset(Db.ResetScope.CLEAR_BINDINGS);
-            update_stmt.bind_string(0, flags.serialize());
+            update_stmt.bind_string(0, flags.message_flags.serialize());
             update_stmt.bind_int(1, Geary.Email.Field.FLAGS);
             update_stmt.bind_rowid(2, id.message_id);
             


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