[geary/wip/goa-error-when-disconnected: 2/3] Fix critical and clean up error handling in FetchEmail replay op



commit 224ccb1834689d1da328c14d3104a56f68e15887
Author: Michael Gratton <mike vee net>
Date:   Sun Mar 3 22:11:49 2019 +1100

    Fix critical and clean up error handling in FetchEmail replay op
    
    Don't assume target email is non-null after fetching from local store
    since it might be if not present and it needs to be fetched from the
    remote. Also, just throw the NOT_FOUND error when local-only, and don't
    bother checking for INCOMPLETE_MESSAGE since it's specified that partial
    is okay anyway.

 .../replay-ops/imap-engine-fetch-email.vala        | 27 +++++++++++++---------
 1 file changed, 16 insertions(+), 11 deletions(-)
---
diff --git a/src/engine/imap-engine/replay-ops/imap-engine-fetch-email.vala 
b/src/engine/imap-engine/replay-ops/imap-engine-fetch-email.vala
index 3edf4347..79688792 100644
--- a/src/engine/imap-engine/replay-ops/imap-engine-fetch-email.vala
+++ b/src/engine/imap-engine/replay-ops/imap-engine-fetch-email.vala
@@ -46,28 +46,33 @@ private class Geary.ImapEngine.FetchEmail : Geary.ImapEngine.SendReplayOperation
             this.uid = yield engine.local_folder.get_uid_async(
                 this.id, NONE, this.cancellable
             );
-            return CONTINUE;
+            return Status.CONTINUE;
         }
 
+        bool local_only = flags.is_all_set(Folder.ListFlags.LOCAL_ONLY);
         Geary.Email? email = null;
         try {
-            email = yield engine.local_folder.fetch_email_async(id, required_fields,
-                ImapDB.Folder.ListFlags.PARTIAL_OK, cancellable);
-        } catch (Error err) {
-            // If NOT_FOUND or INCOMPLETE_MESSAGE, then fall through, otherwise return to sender
-            if (!(err is Geary.EngineError.NOT_FOUND) && !(err is Geary.EngineError.INCOMPLETE_MESSAGE))
+            email = yield engine.local_folder.fetch_email_async(
+                id,
+                required_fields,
+                ImapDB.Folder.ListFlags.PARTIAL_OK,
+                cancellable
+            );
+        } catch (Geary.EngineError.NOT_FOUND err) {
+            if (local_only) {
                 throw err;
+            }
         }
 
         // If returned in full, done
-        if (email.fields.fulfills(required_fields)) {
+        if (email != null && email.fields.fulfills(required_fields)) {
             this.email = email;
             this.remaining_fields = Email.Field.NONE;
             return ReplayOperation.Status.COMPLETED;
-        }
-
-        // If local only, ensure the email has all required fields
-        if (flags.is_all_set(Folder.ListFlags.LOCAL_ONLY)) {
+        } else if (local_only) {
+            // Didn't have an email that fulfills the reqs, but the
+            // caller didn't want to go to the remote, so let them
+            // know
             throw new EngineError.INCOMPLETE_MESSAGE(
                 "Email %s with fields %Xh locally incomplete %s",
                 id.to_string(),


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