From a2940ec7536a8ca9da7c770d47fe796e226f7871 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sat, 31 Aug 2024 10:59:16 +0100 Subject: [PATCH] refactor: rename method as peel Method on newtypes `unwrap` could be confused with the risky method of the same name for Option and Result. --- crates/cli/src/alerts/handlers/notify_user.rs | 2 +- crates/cli/src/alerts/handlers/update_shout.rs | 2 +- crates/cli/src/repo/handlers/advance_main.rs | 2 +- crates/cli/src/repo/handlers/advance_next.rs | 2 +- crates/cli/src/repo/handlers/check_ci_status.rs | 2 +- crates/cli/src/repo/handlers/receive_ci_status.rs | 2 +- crates/cli/src/repo/handlers/receive_repo_config.rs | 2 +- crates/cli/src/repo/handlers/validate_repo.rs | 2 +- crates/cli/src/server/actor/handlers/receive_app_config.rs | 2 +- .../src/server/actor/handlers/receive_valid_app_config.rs | 2 +- crates/cli/src/server/actor/handlers/subscribe_updates.rs | 2 +- crates/core/src/git/tests.rs | 6 +++--- crates/core/src/macros/newtype.rs | 4 ++-- crates/forge-forgejo/src/tests.rs | 6 +++--- 14 files changed, 19 insertions(+), 19 deletions(-) diff --git a/crates/cli/src/alerts/handlers/notify_user.rs b/crates/cli/src/alerts/handlers/notify_user.rs index 00b8a70..6717bd9 100644 --- a/crates/cli/src/alerts/handlers/notify_user.rs +++ b/crates/cli/src/alerts/handlers/notify_user.rs @@ -18,7 +18,7 @@ impl Handler for AlertsActor { }; let net = self.net.clone(); let shout = shout.clone(); - if let Some(user_notification) = self.history.sendable(msg.unwrap()) { + if let Some(user_notification) = self.history.sendable(msg.peel()) { async move { if let Some(webhook_config) = shout.webhook() { send_webhook(&user_notification, webhook_config, &net).await; diff --git a/crates/cli/src/alerts/handlers/update_shout.rs b/crates/cli/src/alerts/handlers/update_shout.rs index 7a7d8f3..7e48841 100644 --- a/crates/cli/src/alerts/handlers/update_shout.rs +++ b/crates/cli/src/alerts/handlers/update_shout.rs @@ -7,6 +7,6 @@ impl Handler for AlertsActor { type Result = (); fn handle(&mut self, msg: UpdateShout, _ctx: &mut Self::Context) -> Self::Result { - self.shout.replace(msg.unwrap()); + self.shout.replace(msg.peel()); } } diff --git a/crates/cli/src/repo/handlers/advance_main.rs b/crates/cli/src/repo/handlers/advance_main.rs index fcd4a50..f1d2adc 100644 --- a/crates/cli/src/repo/handlers/advance_main.rs +++ b/crates/cli/src/repo/handlers/advance_main.rs @@ -29,7 +29,7 @@ impl Handler for RepoActor { let repo_details = self.repo_details.clone(); let addr = ctx.address(); let message_token = self.message_token; - let commit = msg.unwrap(); + let commit = msg.peel(); self.update_tui(RepoUpdate::AdvancingMain { commit: commit.clone(), diff --git a/crates/cli/src/repo/handlers/advance_next.rs b/crates/cli/src/repo/handlers/advance_next.rs index ad3d2b5..2951601 100644 --- a/crates/cli/src/repo/handlers/advance_next.rs +++ b/crates/cli/src/repo/handlers/advance_next.rs @@ -28,7 +28,7 @@ impl Handler for RepoActor { next, main, dev_commit_history, - } = msg.unwrap(); + } = msg.peel(); let repo_details = self.repo_details.clone(); let repo_config = repo_config.clone(); let addr = ctx.address(); diff --git a/crates/cli/src/repo/handlers/check_ci_status.rs b/crates/cli/src/repo/handlers/check_ci_status.rs index 8128998..6f6e103 100644 --- a/crates/cli/src/repo/handlers/check_ci_status.rs +++ b/crates/cli/src/repo/handlers/check_ci_status.rs @@ -20,7 +20,7 @@ impl Handler for RepoActor { let addr = ctx.address(); let forge = self.forge.duplicate(); - let next = msg.unwrap(); + let next = msg.peel(); let log = self.log.clone(); self.update_tui(RepoUpdate::CheckingCI); diff --git a/crates/cli/src/repo/handlers/receive_ci_status.rs b/crates/cli/src/repo/handlers/receive_ci_status.rs index cc1465f..b39fc20 100644 --- a/crates/cli/src/repo/handlers/receive_ci_status.rs +++ b/crates/cli/src/repo/handlers/receive_ci_status.rs @@ -20,7 +20,7 @@ impl Handler for RepoActor { let log = self.log.clone(); logger(log.as_ref(), "start: ReceiveCIStatus"); let addr = ctx.address(); - let (next, status) = msg.unwrap(); + let (next, status) = msg.peel(); let forge_alias = self.repo_details.forge.forge_alias().clone(); let repo_alias = self.repo_details.repo_alias.clone(); let message_token = self.message_token; diff --git a/crates/cli/src/repo/handlers/receive_repo_config.rs b/crates/cli/src/repo/handlers/receive_repo_config.rs index c496be3..c444587 100644 --- a/crates/cli/src/repo/handlers/receive_repo_config.rs +++ b/crates/cli/src/repo/handlers/receive_repo_config.rs @@ -15,7 +15,7 @@ impl Handler for RepoActor { type Result = (); #[instrument(name = "RepoActor::ReceiveRepoConfig", skip_all, fields(repo = %self.repo_details, branches = ?msg))] fn handle(&mut self, msg: ReceiveRepoConfig, ctx: &mut Self::Context) -> Self::Result { - let repo_config = msg.unwrap(); + let repo_config = msg.peel(); self.update_tui(RepoUpdate::ReceiveRepoConfig { repo_config: repo_config.clone(), }); diff --git a/crates/cli/src/repo/handlers/validate_repo.rs b/crates/cli/src/repo/handlers/validate_repo.rs index 095c070..9390963 100644 --- a/crates/cli/src/repo/handlers/validate_repo.rs +++ b/crates/cli/src/repo/handlers/validate_repo.rs @@ -26,7 +26,7 @@ impl Handler for RepoActor { logger(self.log.as_ref(), "start: ValidateRepo"); // Message Token - make sure we are only triggered for the latest/current token - match self.token_status(msg.unwrap()) { + match self.token_status(msg.peel()) { TokenStatus::Current => {} // do nothing TokenStatus::Expired => { logger( diff --git a/crates/cli/src/server/actor/handlers/receive_app_config.rs b/crates/cli/src/server/actor/handlers/receive_app_config.rs index 9a17b4f..a82acbb 100644 --- a/crates/cli/src/server/actor/handlers/receive_app_config.rs +++ b/crates/cli/src/server/actor/handlers/receive_app_config.rs @@ -25,7 +25,7 @@ impl Handler for ServerActor { self.do_send( ReceiveValidAppConfig::new(ValidAppConfig::new( - msg.unwrap(), + msg.peel(), socket_addr, server_storage, )), diff --git a/crates/cli/src/server/actor/handlers/receive_valid_app_config.rs b/crates/cli/src/server/actor/handlers/receive_valid_app_config.rs index 1028cab..cb6d82f 100644 --- a/crates/cli/src/server/actor/handlers/receive_valid_app_config.rs +++ b/crates/cli/src/server/actor/handlers/receive_valid_app_config.rs @@ -26,7 +26,7 @@ impl Handler for ServerActor { app_config, socket_address, storage: server_storage, - } = msg.unwrap(); + } = msg.peel(); // shutdown any existing webhook actor if let Some(webhook_actor_addr) = self.webhook_actor_addr.take() { webhook_actor_addr.do_send(ShutdownWebhook); diff --git a/crates/cli/src/server/actor/handlers/subscribe_updates.rs b/crates/cli/src/server/actor/handlers/subscribe_updates.rs index a11a310..b844bf9 100644 --- a/crates/cli/src/server/actor/handlers/subscribe_updates.rs +++ b/crates/cli/src/server/actor/handlers/subscribe_updates.rs @@ -5,6 +5,6 @@ impl actix::Handler for ServerActor { type Result = (); fn handle(&mut self, msg: SubscribeToUpdates, _ctx: &mut Self::Context) -> Self::Result { - self.subscribers.push(msg.unwrap()); + self.subscribers.push(msg.peel()); } } diff --git a/crates/core/src/git/tests.rs b/crates/core/src/git/tests.rs index 8bc404d..3d17bda 100644 --- a/crates/core/src/git/tests.rs +++ b/crates/core/src/git/tests.rs @@ -240,9 +240,9 @@ pub mod given { } pub fn a_server_repo_config() -> ServerRepoConfig { - let main = a_branch_name().unwrap(); - let next = a_branch_name().unwrap(); - let dev = a_branch_name().unwrap(); + let main = a_branch_name().peel(); + let next = a_branch_name().peel(); + let dev = a_branch_name().peel(); ServerRepoConfig::new( format!("{}/{}", a_name(), a_name()), main.clone(), diff --git a/crates/core/src/macros/newtype.rs b/crates/core/src/macros/newtype.rs index 8704798..ccf8dfd 100644 --- a/crates/core/src/macros/newtype.rs +++ b/crates/core/src/macros/newtype.rs @@ -39,13 +39,13 @@ macro_rules! newtype { } #[allow(clippy::missing_const_for_fn)] #[must_use] - pub fn unwrap(self) -> $type { + pub fn peel(self) -> $type { self.0 } } impl From<$name> for $type { fn from(value: $name) -> $type { - value.unwrap() + value.peel() } } }; diff --git a/crates/forge-forgejo/src/tests.rs b/crates/forge-forgejo/src/tests.rs index 30045ae..adbd9d2 100644 --- a/crates/forge-forgejo/src/tests.rs +++ b/crates/forge-forgejo/src/tests.rs @@ -716,9 +716,9 @@ mod forgejo { } pub fn a_server_repo_config() -> ServerRepoConfig { - let main = a_branch_name().unwrap(); - let next = a_branch_name().unwrap(); - let dev = a_branch_name().unwrap(); + let main = a_branch_name().peel(); + let next = a_branch_name().peel(); + let dev = a_branch_name().peel(); ServerRepoConfig::new( format!("{}/{}", a_name(), a_name()), main.clone(),