Bug 1545793 - Add a specific error code for when we cannot connect to the background copy manager r=agashlin
authorKirk Steuber <ksteuber@mozilla.com>
Mon, 22 Apr 2019 16:21:33 +0000
changeset 470378 dddeb70e81e72d019d4309ac2dd138b7f03c1a2b
parent 470377 44928a7f57454b09e22399f2bb45f715015c267b
child 470379 6e95f85fb09f4286e751927b89be768b7a0a4945
push id112868
push useropoprus@mozilla.com
push dateMon, 22 Apr 2019 22:19:22 +0000
treeherdermozilla-inbound@24537856cc88 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersagashlin
bugs1545793
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1545793 - Add a specific error code for when we cannot connect to the background copy manager r=agashlin Differential Revision: https://phabricator.services.mozilla.com/D28256
toolkit/components/bitsdownload/bits_client/src/bits_protocol.rs
toolkit/components/bitsdownload/bits_client/src/in_process/mod.rs
--- a/toolkit/components/bitsdownload/bits_client/src/bits_protocol.rs
+++ b/toolkit/components/bitsdownload/bits_client/src/bits_protocol.rs
@@ -89,16 +89,18 @@ pub enum StartJobFailure {
     #[fail(display = "Create job: {}", _0)]
     Create(HResultMessage),
     #[fail(display = "Add file to job: {}", _0)]
     AddFile(HResultMessage),
     #[fail(display = "Apply settings to job: {}", _0)]
     ApplySettings(HResultMessage),
     #[fail(display = "Resume job: {}", _0)]
     Resume(HResultMessage),
+    #[fail(display = "Connect to BackgroundCopyManager: {}", _0)]
+    ConnectBcm(HResultMessage),
     #[fail(display = "BITS error: {}", _0)]
     OtherBITS(HResultMessage),
     #[fail(display = "Other failure: {}", _0)]
     Other(String),
 }
 
 // Monitor Job
 #[doc(hidden)]
@@ -119,16 +121,18 @@ impl CommandType for MonitorJobCommand {
 #[derive(Clone, Debug, Fail)]
 pub enum MonitorJobFailure {
     #[fail(display = "Argument validation failed: {}", _0)]
     ArgumentValidation(String),
     #[fail(display = "Job not found")]
     NotFound,
     #[fail(display = "Get job: {}", _0)]
     GetJob(HResultMessage),
+    #[fail(display = "Connect to BackgroundCopyManager: {}", _0)]
+    ConnectBcm(HResultMessage),
     #[fail(display = "BITS error: {}", _0)]
     OtherBITS(HResultMessage),
     #[fail(display = "Other failure: {}", _0)]
     Other(String),
 }
 
 // Suspend Job
 #[doc(hidden)]
@@ -148,16 +152,18 @@ impl CommandType for SuspendJobCommand {
 #[derive(Clone, Debug, Fail)]
 pub enum SuspendJobFailure {
     #[fail(display = "Job not found")]
     NotFound,
     #[fail(display = "Get job: {}", _0)]
     GetJob(HResultMessage),
     #[fail(display = "Suspend job: {}", _0)]
     SuspendJob(HResultMessage),
+    #[fail(display = "Connect to BackgroundCopyManager: {}", _0)]
+    ConnectBcm(HResultMessage),
     #[fail(display = "BITS error: {}", _0)]
     OtherBITS(HResultMessage),
     #[fail(display = "Other failure: {}", _0)]
     Other(String),
 }
 
 // Resume Job
 #[doc(hidden)]
@@ -177,16 +183,18 @@ impl CommandType for ResumeJobCommand {
 #[derive(Clone, Debug, Fail)]
 pub enum ResumeJobFailure {
     #[fail(display = "Job not found")]
     NotFound,
     #[fail(display = "Get job: {}", _0)]
     GetJob(HResultMessage),
     #[fail(display = "Resume job: {}", _0)]
     ResumeJob(HResultMessage),
+    #[fail(display = "Connect to BackgroundCopyManager: {}", _0)]
+    ConnectBcm(HResultMessage),
     #[fail(display = "BITS error: {}", _0)]
     OtherBITS(HResultMessage),
     #[fail(display = "Other failure: {}", _0)]
     Other(String),
 }
 
 // Set Job Priority
 #[doc(hidden)]
@@ -207,16 +215,18 @@ impl CommandType for SetJobPriorityComma
 #[derive(Clone, Debug, Fail)]
 pub enum SetJobPriorityFailure {
     #[fail(display = "Job not found")]
     NotFound,
     #[fail(display = "Get job: {}", _0)]
     GetJob(HResultMessage),
     #[fail(display = "Apply settings to job: {}", _0)]
     ApplySettings(HResultMessage),
+    #[fail(display = "Connect to BackgroundCopyManager: {}", _0)]
+    ConnectBcm(HResultMessage),
     #[fail(display = "BITS error: {}", _0)]
     OtherBITS(HResultMessage),
     #[fail(display = "Other failure: {}", _0)]
     Other(String),
 }
 
 // Set Update Interval
 #[doc(hidden)]
@@ -264,16 +274,18 @@ pub enum CompleteJobFailure {
     #[fail(display = "Job not found")]
     NotFound,
     #[fail(display = "Get job: {}", _0)]
     GetJob(HResultMessage),
     #[fail(display = "Complete job: {}", _0)]
     CompleteJob(HResultMessage),
     #[fail(display = "Job only partially completed")]
     PartialComplete,
+    #[fail(display = "Connect to BackgroundCopyManager: {}", _0)]
+    ConnectBcm(HResultMessage),
     #[fail(display = "BITS error: {}", _0)]
     OtherBITS(HResultMessage),
     #[fail(display = "Other failure: {}", _0)]
     Other(String),
 }
 
 // Cancel Job
 #[doc(hidden)]
@@ -293,16 +305,18 @@ impl CommandType for CancelJobCommand {
 #[derive(Clone, Debug, Fail)]
 pub enum CancelJobFailure {
     #[fail(display = "Job not found")]
     NotFound,
     #[fail(display = "Get job: {}", _0)]
     GetJob(HResultMessage),
     #[fail(display = "Cancel job: {}", _0)]
     CancelJob(HResultMessage),
+    #[fail(display = "Connect to BackgroundCopyManager: {}", _0)]
+    ConnectBcm(HResultMessage),
     #[fail(display = "BITS error: {}", _0)]
     OtherBITS(HResultMessage),
     #[fail(display = "Other failure: {}", _0)]
     Other(String),
 }
 
 /// Job status report
 ///
--- a/toolkit/components/bitsdownload/bits_client/src/in_process/mod.rs
+++ b/toolkit/components/bitsdownload/bits_client/src/in_process/mod.rs
@@ -16,17 +16,22 @@ use guid_win::Guid;
 
 use bits_protocol::*;
 
 use super::Error;
 
 // This is a macro in order to use the NotFound and GetJob variants from whatever enum is in scope.
 macro_rules! get_job {
     ($bcm:ident, $guid:expr, $name:expr) => {{
-        $bcm = BackgroundCopyManager::connect().map_err(|e| Other(e.to_string()))?;
+        $bcm = BackgroundCopyManager::connect().map_err(|e| {
+            ConnectBcm(HResultMessage {
+                hr: e.code(),
+                message: e.to_string(),
+            })
+        })?;
         $bcm.find_job_by_guid_and_name($guid, $name)
             .map_err(|e| GetJob($crate::in_process::format_error(&$bcm, e)))?
             .ok_or(NotFound)?
     }};
 }
 
 fn format_error(bcm: &BackgroundCopyManager, error: comedy::HResult) -> HResultMessage {
     let bits_description = bcm.get_error_description(error.code()).ok();
@@ -94,17 +99,22 @@ impl InProcessClient {
                 )));
             }
         }
 
         // TODO: Should the job be explicitly cleaned up if this fn can't return success?
         // If the job is dropped before `AddFile` succeeds, I think it automatically gets
         // deleted from the queue. There is only one fallible call after that (`Resume`).
 
-        let bcm = BackgroundCopyManager::connect().map_err(|e| Other(e.to_string()))?;
+        let bcm = BackgroundCopyManager::connect().map_err(|e| {
+            ConnectBcm(HResultMessage {
+                hr: e.code(),
+                message: e.to_string(),
+            })
+        })?;
         let mut job = bcm
             .create_job(&self.job_name)
             .map_err(|e| Create(format_error(&bcm, e)))?;
 
         let guid = job.guid().map_err(|e| OtherBITS(format_error(&bcm, e)))?;
 
         (|| {
             job.set_proxy_usage(proxy_usage)?;