Bug 1736526 - activity manager: don't throw on missing thing to remove, when removing. r=henry
authorMagnus Melin <mkmelin+mozilla@iki.fi>
Tue, 16 Nov 2021 11:59:18 +0200
changeset 34298 246be8ca932f9aa972803eb5a21e5a4cd98f68a1
parent 34297 2261682906df0d5724e2cf834e30002ff7cbc069
child 34299 c5c4c937c2b14293d4f02ce834e9e6d36704f266
push id19369
push usermkmelin@iki.fi
push dateTue, 16 Nov 2021 10:03:00 +0000
treeherdercomm-central@246be8ca932f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershenry
bugs1736526
Bug 1736526 - activity manager: don't throw on missing thing to remove, when removing. r=henry Differential Revision: https://phabricator.services.mozilla.com/D131123
mail/components/activity/ActivityManager.jsm
mail/components/activity/nsIActivityManager.idl
--- a/mail/components/activity/ActivityManager.jsm
+++ b/mail/components/activity/ActivityManager.jsm
@@ -74,30 +74,27 @@ ActivityManager.prototype = {
       // for some reason exceptions don't end up on the console if we don't
       // explicitly log them.
       this.log.error("Exception: " + e);
       throw e;
     }
   },
 
   removeActivity(aID) {
-    let activity;
-    try {
-      activity = this.getActivity(aID);
-    } catch (e) {
-      this.log.error("Exception: " + e);
-      throw e;
+    let activity = this.getActivity(aID);
+    if (!activity) {
+      return; // Nothing to remove.
     }
 
     // make sure that the activity is not in-progress state
     if (
       activity instanceof Ci.nsIActivityProcess &&
       activity.state == Ci.nsIActivityProcess.STATE_INPROGRESS
     ) {
-      throw Components.Exception("", Cr.NS_ERROR_FAILURE);
+      throw Components.Exception(`Activity in progress`, Cr.NS_ERROR_FAILURE);
     }
 
     // remove the activity
     this._activities.delete(aID);
 
     // notify all the listeners
     for (let value of this._listeners) {
       try {
@@ -126,19 +123,16 @@ ActivityManager.prototype = {
         }
       } else {
         this.removeActivity(id);
       }
     }
   },
 
   getActivity(aID) {
-    if (!this._activities.has(aID)) {
-      throw Components.Exception("", Cr.NS_ERROR_NOT_AVAILABLE);
-    }
     return this._activities.get(aID);
   },
 
   containsActivity(aID) {
     return this._activities.has(aID);
   },
 
   getActivities() {
--- a/mail/components/activity/nsIActivityManager.idl
+++ b/mail/components/activity/nsIActivityManager.idl
@@ -71,29 +71,27 @@ interface nsIActivityManager : nsISuppor
 
   /**
    * Removes the activity with the given id if it's not currently
    * in-progress.
    *
    * @param aID The unique ID of the activity.
    *
    * @throws NS_ERROR_FAILURE if the activity is in-progress.
-   * @throws NS_ERROR_NOT_AVAILABLE if the activity is not in the list.
    */
   void removeActivity(in unsigned long aID);
 
   /**
    * Retrieves an activity managed by the activity manager. This can be one that
    * is in progress, or one that has completed in the past and is stored in the
    * persistent store.
    *
    * @param aID The unique ID of the activity.
    *
-   * @return The activity with the specified ID.
-   * @throws NS_ERROR_NOT_AVAILABLE if the activity is not in the list.
+   * @return The activity with the specified ID, or null if not found.
    */
   nsIActivity getActivity(in unsigned long aID);
 
   /**
    * Tests whether the activity in question in the activity list or not.
    */
   boolean containsActivity(in unsigned long aID);