diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-11-26 07:48:30 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-11-26 12:26:47 +0000 |
| commit | a0593e3aa9b19b9ca3c3881cbe0d9d207fe46d2c (patch) | |
| tree | 3482e7c558eff09cc91604ad6ddcd02cf2c94699 /src/bin/ngit/sub_commands/list.rs | |
| parent | 1332c625b75fce616e06b415c99a068bc45c8210 (diff) | |
refactor: err msgs 'cannot' > 'failed to'
in nearly all cases 'cannot' was used when an action was tried and
failed. 'failed to' is strictly better because:
* just because the action didn't work that time doesnt mean it
cannot work
* it is better at drawing the users attention to a problem
Diffstat (limited to 'src/bin/ngit/sub_commands/list.rs')
| -rw-r--r-- | src/bin/ngit/sub_commands/list.rs | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/src/bin/ngit/sub_commands/list.rs b/src/bin/ngit/sub_commands/list.rs index 7717dce..1e8ecc4 100644 --- a/src/bin/ngit/sub_commands/list.rs +++ b/src/bin/ngit/sub_commands/list.rs | |||
| @@ -24,7 +24,7 @@ use crate::{ | |||
| 24 | 24 | ||
| 25 | #[allow(clippy::too_many_lines)] | 25 | #[allow(clippy::too_many_lines)] |
| 26 | pub async fn launch() -> Result<()> { | 26 | pub async fn launch() -> Result<()> { |
| 27 | let git_repo = Repo::discover().context("cannot find a git repository")?; | 27 | let git_repo = Repo::discover().context("failed to find a git repository")?; |
| 28 | let git_repo_path = git_repo.get_path()?; | 28 | let git_repo_path = git_repo.get_path()?; |
| 29 | 29 | ||
| 30 | // TODO: check for empty repo | 30 | // TODO: check for empty repo |
| @@ -179,7 +179,7 @@ pub async fn launch() -> Result<()> { | |||
| 179 | } | 179 | } |
| 180 | 180 | ||
| 181 | let cover_letter = event_to_cover_letter(proposals_for_status[selected_index]) | 181 | let cover_letter = event_to_cover_letter(proposals_for_status[selected_index]) |
| 182 | .context("cannot extract proposal details from proposal root event")?; | 182 | .context("failed to extract proposal details from proposal root event")?; |
| 183 | 183 | ||
| 184 | let commits_events: Vec<nostr::Event> = get_all_proposal_patch_events_from_cache( | 184 | let commits_events: Vec<nostr::Event> = get_all_proposal_patch_events_from_cache( |
| 185 | git_repo_path, | 185 | git_repo_path, |
| @@ -195,7 +195,7 @@ pub async fn launch() -> Result<()> { | |||
| 195 | PromptConfirmParms::default() | 195 | PromptConfirmParms::default() |
| 196 | .with_default(true) | 196 | .with_default(true) |
| 197 | .with_prompt( | 197 | .with_prompt( |
| 198 | "cannot find any patches on this proposal. choose another proposal?", | 198 | "failed to find any patches on this proposal. choose another proposal?", |
| 199 | ), | 199 | ), |
| 200 | )? { | 200 | )? { |
| 201 | continue; | 201 | continue; |
| @@ -275,7 +275,7 @@ pub async fn launch() -> Result<()> { | |||
| 275 | )?, | 275 | )?, |
| 276 | "parent-commit", | 276 | "parent-commit", |
| 277 | )?) | 277 | )?) |
| 278 | .context("cannot get valid parent commit id from patch")?; | 278 | .context("failed to get valid parent commit id from patch")?; |
| 279 | 279 | ||
| 280 | let (main_branch_name, master_tip) = git_repo.get_main_or_master_branch()?; | 280 | let (main_branch_name, master_tip) = git_repo.get_main_or_master_branch()?; |
| 281 | 281 | ||
| @@ -305,9 +305,9 @@ pub async fn launch() -> Result<()> { | |||
| 305 | &get_commit_id_from_patch(most_recent_proposal_patch_chain.first().context( | 305 | &get_commit_id_from_patch(most_recent_proposal_patch_chain.first().context( |
| 306 | "there should be at least one patch as we have already checked for this", | 306 | "there should be at least one patch as we have already checked for this", |
| 307 | )?) | 307 | )?) |
| 308 | .context("cannot get valid commit_id from patch")?, | 308 | .context("failed to get valid commit_id from patch")?, |
| 309 | ) | 309 | ) |
| 310 | .context("cannot get valid commit_id from patch")?; | 310 | .context("failed to get valid commit_id from patch")?; |
| 311 | 311 | ||
| 312 | let (_, proposal_behind_main) = | 312 | let (_, proposal_behind_main) = |
| 313 | git_repo.get_commits_ahead_behind(&master_tip, &proposal_base_commit)?; | 313 | git_repo.get_commits_ahead_behind(&master_tip, &proposal_base_commit)?; |
| @@ -332,7 +332,7 @@ pub async fn launch() -> Result<()> { | |||
| 332 | &cover_letter.get_branch_name()?, | 332 | &cover_letter.get_branch_name()?, |
| 333 | most_recent_proposal_patch_chain, | 333 | most_recent_proposal_patch_chain, |
| 334 | ) | 334 | ) |
| 335 | .context("cannot apply patch chain")?; | 335 | .context("failed to apply patch chain")?; |
| 336 | 336 | ||
| 337 | println!( | 337 | println!( |
| 338 | "checked out proposal as '{}' branch", | 338 | "checked out proposal as '{}' branch", |
| @@ -427,7 +427,7 @@ pub async fn launch() -> Result<()> { | |||
| 427 | &cover_letter.get_branch_name()?, | 427 | &cover_letter.get_branch_name()?, |
| 428 | most_recent_proposal_patch_chain, | 428 | most_recent_proposal_patch_chain, |
| 429 | ) | 429 | ) |
| 430 | .context("cannot apply patch chain")?; | 430 | .context("failed to apply patch chain")?; |
| 431 | println!( | 431 | println!( |
| 432 | "checked out proposal branch and applied {} appendments ({} ahead {} behind '{main_branch_name}')", | 432 | "checked out proposal branch and applied {} appendments ({} ahead {} behind '{main_branch_name}')", |
| 433 | &index, | 433 | &index, |
| @@ -484,7 +484,7 @@ pub async fn launch() -> Result<()> { | |||
| 484 | &cover_letter.get_branch_name()?, | 484 | &cover_letter.get_branch_name()?, |
| 485 | most_recent_proposal_patch_chain, | 485 | most_recent_proposal_patch_chain, |
| 486 | ) | 486 | ) |
| 487 | .context("cannot apply patch chain")?; | 487 | .context("failed to apply patch chain")?; |
| 488 | println!( | 488 | println!( |
| 489 | "checked out new version of proposal ({} ahead {} behind '{main_branch_name}'), replacing old version ({} ahead {} behind '{main_branch_name}')", | 489 | "checked out new version of proposal ({} ahead {} behind '{main_branch_name}'), replacing old version ({} ahead {} behind '{main_branch_name}')", |
| 490 | chain_length, | 490 | chain_length, |
| @@ -517,7 +517,9 @@ pub async fn launch() -> Result<()> { | |||
| 517 | else if git_repo.ancestor_of(&local_branch_tip, &proposal_tip)? { | 517 | else if git_repo.ancestor_of(&local_branch_tip, &proposal_tip)? { |
| 518 | let (local_ahead_of_proposal, _) = git_repo | 518 | let (local_ahead_of_proposal, _) = git_repo |
| 519 | .get_commits_ahead_behind(&proposal_tip, &local_branch_tip) | 519 | .get_commits_ahead_behind(&proposal_tip, &local_branch_tip) |
| 520 | .context("cannot get commits ahead behind for propsal_top and local_branch_tip")?; | 520 | .context( |
| 521 | "failed to get commits ahead behind for propsal_top and local_branch_tip", | ||
| 522 | )?; | ||
| 521 | 523 | ||
| 522 | println!( | 524 | println!( |
| 523 | "local proposal branch exists with {} unpublished commits on top of the most up-to-date version of the proposal ({} ahead {} behind '{main_branch_name}')", | 525 | "local proposal branch exists with {} unpublished commits on top of the most up-to-date version of the proposal ({} ahead {} behind '{main_branch_name}')", |
| @@ -624,7 +626,7 @@ pub async fn launch() -> Result<()> { | |||
| 624 | &cover_letter.get_branch_name()?, | 626 | &cover_letter.get_branch_name()?, |
| 625 | most_recent_proposal_patch_chain, | 627 | most_recent_proposal_patch_chain, |
| 626 | ) | 628 | ) |
| 627 | .context("cannot apply patch chain")?; | 629 | .context("failed to apply patch chain")?; |
| 628 | 630 | ||
| 629 | git_repo.checkout(&cover_letter.get_branch_name()?)?; | 631 | git_repo.checkout(&cover_letter.get_branch_name()?)?; |
| 630 | println!( | 632 | println!( |
| @@ -715,7 +717,7 @@ fn save_patches_to_dir(mut patches: Vec<nostr::Event>, git_repo: &Repo) -> Resul | |||
| 715 | fn check_clean(git_repo: &Repo) -> Result<()> { | 717 | fn check_clean(git_repo: &Repo) -> Result<()> { |
| 716 | if git_repo.has_outstanding_changes()? { | 718 | if git_repo.has_outstanding_changes()? { |
| 717 | bail!( | 719 | bail!( |
| 718 | "cannot pull proposal branch when repository is not clean. discard or stash (un)staged changes and try again." | 720 | "failed to pull proposal branch when repository is not clean. discard or stash (un)staged changes and try again." |
| 719 | ); | 721 | ); |
| 720 | } | 722 | } |
| 721 | Ok(()) | 723 | Ok(()) |