diff options
author | Lukasz Woznicki <75632179+makr11st@users.noreply.github.com> | 2022-05-04 10:23:26 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-04 10:23:26 +0100 |
commit | 16ddae45cea0c605aeb4e100cff9a855d12e839c (patch) | |
tree | 99530f5682498a54169f13838e00562c919012a7 /crates/core | |
parent | fa9fcd90abf6c33760cfe2a529b2bfbd677405df (diff) | |
parent | e020a647657ef4bb42845d5affe189cdf68a253f (diff) |
Merge pull request #1068 from makr11st/feature/759_tedge_disconnect_report_error
#759 tedge disconnect falsely returns exit code 0 when disabling or stopping of a component fails
Diffstat (limited to 'crates/core')
-rw-r--r-- | crates/core/tedge/src/cli/disconnect/disconnect_bridge.rs | 12 | ||||
-rw-r--r-- | crates/core/tedge/src/cli/disconnect/error.rs | 9 |
2 files changed, 15 insertions, 6 deletions
diff --git a/crates/core/tedge/src/cli/disconnect/disconnect_bridge.rs b/crates/core/tedge/src/cli/disconnect/disconnect_bridge.rs index be6d1df9..bc6e4f12 100644 --- a/crates/core/tedge/src/cli/disconnect/disconnect_bridge.rs +++ b/crates/core/tedge/src/cli/disconnect/disconnect_bridge.rs @@ -77,18 +77,24 @@ impl DisconnectBridgeCommand { // Ignore failure let _ = self.apply_changes_to_mosquitto(); + let mut failed = false; // Only C8Y changes the status of tedge-mapper if self.use_mapper && which("tedge_mapper").is_ok() { - self.service_manager() + failed = self + .service_manager() .stop_and_disable_service(self.cloud.dependent_mapper_service(), std::io::stdout()); } if self.use_agent && which("tedge_agent").is_ok() { - self.service_manager() + failed = self + .service_manager() .stop_and_disable_service(SystemService::TEdgeSMAgent, std::io::stdout()); } - Ok(()) + match failed { + false => Ok(()), + true => Err(DisconnectBridgeError::ServiceFailed), + } } fn remove_bridge_config_file(&self) -> Result<(), DisconnectBridgeError> { diff --git a/crates/core/tedge/src/cli/disconnect/error.rs b/crates/core/tedge/src/cli/disconnect/error.rs index fd38bf0d..a3bc5b43 100644 --- a/crates/core/tedge/src/cli/disconnect/error.rs +++ b/crates/core/tedge/src/cli/disconnect/error.rs @@ -2,6 +2,9 @@ use std::path::PathBuf; #[derive(thiserror::Error, Debug)] pub enum DisconnectBridgeError { + #[error("Bridge file does not exist.")] + BridgeFileDoesNotExist, + #[error(transparent)] Configuration(#[from] crate::ConfigError), @@ -11,9 +14,9 @@ pub enum DisconnectBridgeError { #[error(transparent)] IoError(#[from] std::io::Error), + #[error("Service operation failed.")] + ServiceFailed, + #[error(transparent)] SystemServiceError(#[from] crate::system_services::SystemServiceError), - - #[error("Bridge file does not exist.")] - BridgeFileDoesNotExist, } |