From a0593e3aa9b19b9ca3c3881cbe0d9d207fe46d2c Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Tue, 26 Nov 2024 07:48:30 +0000 Subject: 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 --- src/bin/git_remote_nostr/fetch.rs | 4 ++-- src/bin/git_remote_nostr/list.rs | 2 +- src/bin/git_remote_nostr/push.rs | 16 ++++++++-------- src/bin/ngit/sub_commands/fetch.rs | 2 +- src/bin/ngit/sub_commands/init.rs | 2 +- src/bin/ngit/sub_commands/list.rs | 26 ++++++++++++++------------ src/bin/ngit/sub_commands/login.rs | 2 +- src/bin/ngit/sub_commands/pull.rs | 22 +++++++++++----------- src/bin/ngit/sub_commands/push.rs | 10 +++++----- src/bin/ngit/sub_commands/send.rs | 4 ++-- 10 files changed, 46 insertions(+), 44 deletions(-) (limited to 'src/bin') diff --git a/src/bin/git_remote_nostr/fetch.rs b/src/bin/git_remote_nostr/fetch.rs index a972a2f..90387f3 100644 --- a/src/bin/git_remote_nostr/fetch.rs +++ b/src/bin/git_remote_nostr/fetch.rs @@ -110,7 +110,7 @@ pub fn make_commits_for_proposal( let commit_id = git_repo .create_commit_from_patch(patch, Some(tip_commit_id.clone())) .context(format!( - "cannot create commit for patch {}", + "failed to create commit for patch {}", nip19::Nip19Event { event_id: patch.id, author: Some(patch.pubkey), @@ -146,7 +146,7 @@ async fn fetch_proposals( { if let Err(error) = make_commits_for_proposal(git_repo, repo_ref, patches) { term.write_line( - format!("WARNING: cannot create branch for {refstr}, error: {error}",) + format!("WARNING: failed to create branch for {refstr}, error: {error}",) .as_str(), )?; break; diff --git a/src/bin/git_remote_nostr/list.rs b/src/bin/git_remote_nostr/list.rs index daff1b6..9171544 100644 --- a/src/bin/git_remote_nostr/list.rs +++ b/src/bin/git_remote_nostr/list.rs @@ -163,7 +163,7 @@ async fn get_open_proposals_state( } Err(error) => { let _ = term.write_line( - format!("WARNING: cannot fetch branch {branch_name} error: {error}") + format!("WARNING: failed to fetch branch {branch_name} error: {error}") .as_str(), ); } diff --git a/src/bin/git_remote_nostr/push.rs b/src/bin/git_remote_nostr/push.rs index 7161c5d..381a45e 100644 --- a/src/bin/git_remote_nostr/push.rs +++ b/src/bin/git_remote_nostr/push.rs @@ -92,7 +92,7 @@ pub async fn run_push( list_outputs.get(url).unwrap().to_owned() } else { bail!( - "cannot connect to git servers: {}", + "failed to connect to git servers: {}", repo_ref.git_server.join(" ") ); } @@ -245,7 +245,7 @@ pub async fn run_push( &[], ) .await - .context("cannot make patch event from commit")?; + .context("failed to make patch event from commit")?; events.push(new_patch.clone()); parent_patch = new_patch; } @@ -259,7 +259,7 @@ pub async fn run_push( ) .unwrap(); println!( - "error {to} cannot fastforward as newer patches found on proposal" + "error {to} failed to fastforward as newer patches found on proposal" ); rejected_proposal_refspecs.push(refspec.to_string()); } @@ -1089,7 +1089,7 @@ fn update_remote_refs_pushed( } } else { let commit = reference_to_commit(git_repo, from) - .context(format!("cannot get commit of reference {from}"))?; + .context(format!("failed to get commit of reference {from}"))?; if let Ok(mut remote_ref) = git_repo.find_reference(&target_ref_name) { remote_ref.set_target(commit, "updated by nostr remote helper")?; } else { @@ -1142,9 +1142,9 @@ fn refspec_remote_ref_name( fn reference_to_commit(git_repo: &Repository, reference: &str) -> Result { Ok(git_repo .find_reference(reference) - .context(format!("cannot find reference: {reference}"))? + .context(format!("failed to find reference: {reference}"))? .peel_to_commit() - .context(format!("cannot get commit from reference: {reference}"))? + .context(format!("failed to get commit from reference: {reference}"))? .id()) } @@ -1152,13 +1152,13 @@ fn reference_to_commit(git_repo: &Repository, reference: &str) -> Result { fn reference_to_ref_value(git_repo: &Repository, reference: &str) -> Result { let reference_obj = git_repo .find_reference(reference) - .context(format!("cannot find reference: {reference}"))?; + .context(format!("failed to find reference: {reference}"))?; if let Some(symref) = reference_obj.symbolic_target() { Ok(symref.to_string()) } else { Ok(reference_obj .peel_to_commit() - .context(format!("cannot get commit from reference: {reference}"))? + .context(format!("failed to get commit from reference: {reference}"))? .id() .to_string()) } diff --git a/src/bin/ngit/sub_commands/fetch.rs b/src/bin/ngit/sub_commands/fetch.rs index c69f1c5..dc548fd 100644 --- a/src/bin/ngit/sub_commands/fetch.rs +++ b/src/bin/ngit/sub_commands/fetch.rs @@ -20,7 +20,7 @@ pub struct SubCommandArgs { pub async fn launch(args: &Cli, command_args: &SubCommandArgs) -> Result<()> { let _ = args; - let git_repo = Repo::discover().context("cannot find a git repository")?; + let git_repo = Repo::discover().context("failed to find a git repository")?; let client = Client::default(); let repo_coordinates = if command_args.repo.is_empty() { get_repo_coordinates(&git_repo, &client).await? diff --git a/src/bin/ngit/sub_commands/init.rs b/src/bin/ngit/sub_commands/init.rs index 146a29c..9f5093e 100644 --- a/src/bin/ngit/sub_commands/init.rs +++ b/src/bin/ngit/sub_commands/init.rs @@ -47,7 +47,7 @@ pub struct SubCommandArgs { #[allow(clippy::too_many_lines)] pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { - let git_repo = Repo::discover().context("cannot find a git repository")?; + let git_repo = Repo::discover().context("failed to find a git repository")?; let git_repo_path = git_repo.get_path()?; let root_commit = git_repo 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::{ #[allow(clippy::too_many_lines)] pub async fn launch() -> Result<()> { - let git_repo = Repo::discover().context("cannot find a git repository")?; + let git_repo = Repo::discover().context("failed to find a git repository")?; let git_repo_path = git_repo.get_path()?; // TODO: check for empty repo @@ -179,7 +179,7 @@ pub async fn launch() -> Result<()> { } let cover_letter = event_to_cover_letter(proposals_for_status[selected_index]) - .context("cannot extract proposal details from proposal root event")?; + .context("failed to extract proposal details from proposal root event")?; let commits_events: Vec = get_all_proposal_patch_events_from_cache( git_repo_path, @@ -195,7 +195,7 @@ pub async fn launch() -> Result<()> { PromptConfirmParms::default() .with_default(true) .with_prompt( - "cannot find any patches on this proposal. choose another proposal?", + "failed to find any patches on this proposal. choose another proposal?", ), )? { continue; @@ -275,7 +275,7 @@ pub async fn launch() -> Result<()> { )?, "parent-commit", )?) - .context("cannot get valid parent commit id from patch")?; + .context("failed to get valid parent commit id from patch")?; let (main_branch_name, master_tip) = git_repo.get_main_or_master_branch()?; @@ -305,9 +305,9 @@ pub async fn launch() -> Result<()> { &get_commit_id_from_patch(most_recent_proposal_patch_chain.first().context( "there should be at least one patch as we have already checked for this", )?) - .context("cannot get valid commit_id from patch")?, + .context("failed to get valid commit_id from patch")?, ) - .context("cannot get valid commit_id from patch")?; + .context("failed to get valid commit_id from patch")?; let (_, proposal_behind_main) = git_repo.get_commits_ahead_behind(&master_tip, &proposal_base_commit)?; @@ -332,7 +332,7 @@ pub async fn launch() -> Result<()> { &cover_letter.get_branch_name()?, most_recent_proposal_patch_chain, ) - .context("cannot apply patch chain")?; + .context("failed to apply patch chain")?; println!( "checked out proposal as '{}' branch", @@ -427,7 +427,7 @@ pub async fn launch() -> Result<()> { &cover_letter.get_branch_name()?, most_recent_proposal_patch_chain, ) - .context("cannot apply patch chain")?; + .context("failed to apply patch chain")?; println!( "checked out proposal branch and applied {} appendments ({} ahead {} behind '{main_branch_name}')", &index, @@ -484,7 +484,7 @@ pub async fn launch() -> Result<()> { &cover_letter.get_branch_name()?, most_recent_proposal_patch_chain, ) - .context("cannot apply patch chain")?; + .context("failed to apply patch chain")?; println!( "checked out new version of proposal ({} ahead {} behind '{main_branch_name}'), replacing old version ({} ahead {} behind '{main_branch_name}')", chain_length, @@ -517,7 +517,9 @@ pub async fn launch() -> Result<()> { else if git_repo.ancestor_of(&local_branch_tip, &proposal_tip)? { let (local_ahead_of_proposal, _) = git_repo .get_commits_ahead_behind(&proposal_tip, &local_branch_tip) - .context("cannot get commits ahead behind for propsal_top and local_branch_tip")?; + .context( + "failed to get commits ahead behind for propsal_top and local_branch_tip", + )?; println!( "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<()> { &cover_letter.get_branch_name()?, most_recent_proposal_patch_chain, ) - .context("cannot apply patch chain")?; + .context("failed to apply patch chain")?; git_repo.checkout(&cover_letter.get_branch_name()?)?; println!( @@ -715,7 +717,7 @@ fn save_patches_to_dir(mut patches: Vec, git_repo: &Repo) -> Resul fn check_clean(git_repo: &Repo) -> Result<()> { if git_repo.has_outstanding_changes()? { bail!( - "cannot pull proposal branch when repository is not clean. discard or stash (un)staged changes and try again." + "failed to pull proposal branch when repository is not clean. discard or stash (un)staged changes and try again." ); } Ok(()) diff --git a/src/bin/ngit/sub_commands/login.rs b/src/bin/ngit/sub_commands/login.rs index 53da154..16026dd 100644 --- a/src/bin/ngit/sub_commands/login.rs +++ b/src/bin/ngit/sub_commands/login.rs @@ -33,7 +33,7 @@ pub async fn launch(args: &Cli, command_args: &SubCommandArgs) -> Result<()> { Some(Client::default()) }; - let git_repo_result = Repo::discover().context("cannot find a git repository"); + let git_repo_result = Repo::discover().context("failed to find a git repository"); let git_repo = { match git_repo_result { Ok(git_repo) => Some(git_repo), diff --git a/src/bin/ngit/sub_commands/pull.rs b/src/bin/ngit/sub_commands/pull.rs index 77a65e9..f459c8e 100644 --- a/src/bin/ngit/sub_commands/pull.rs +++ b/src/bin/ngit/sub_commands/pull.rs @@ -14,7 +14,7 @@ use crate::{ #[allow(clippy::too_many_lines)] pub async fn launch() -> Result<()> { - let git_repo = Repo::discover().context("cannot find a git repository")?; + let git_repo = Repo::discover().context("failed to find a git repository")?; let git_repo_path = git_repo.get_path()?; let (main_or_master_branch_name, _) = git_repo @@ -23,7 +23,7 @@ pub async fn launch() -> Result<()> { let branch_name = git_repo .get_checked_out_branch_name() - .context("cannot get checked out branch name")?; + .context("failed to get checked out branch name")?; if branch_name == main_or_master_branch_name { bail!("checkout a branch associated with a proposal first") @@ -50,7 +50,7 @@ pub async fn launch() -> Result<()> { is_event_proposal_root_for_branch(e, &branch_name, &logged_in_public_key) .unwrap_or(false) }) - .context("cannot find proposal that matches the current branch name")? + .context("failed to find proposal that matches the current branch name")? .clone(); let commit_events = @@ -59,7 +59,7 @@ pub async fn launch() -> Result<()> { let most_recent_proposal_patch_chain = get_most_recent_patch_with_ancestors(commit_events.clone()) - .context("cannot get most recent patch for proposal")?; + .context("failed to get most recent patch for proposal")?; let local_branch_tip = git_repo.get_tip_of_branch(&branch_name)?; @@ -74,7 +74,7 @@ pub async fn launch() -> Result<()> { .context("there should be at least one patch as we have already checked for this")?, "parent-commit", )?) - .context("cannot get valid parent commit id from patch")?; + .context("failed to get valid parent commit id from patch")?; let (_, proposal_behind_main) = git_repo.get_commits_ahead_behind(&master_tip, &proposal_base_commit)?; @@ -84,9 +84,9 @@ pub async fn launch() -> Result<()> { &get_commit_id_from_patch(most_recent_proposal_patch_chain.first().context( "there should be at least one patch as we have already checked for this", )?) - .context("cannot get valid commit_id from patch")?, + .context("failed to get valid commit_id from patch")?, ) - .context("cannot get valid commit_id from patch")?; + .context("failed to get valid commit_id from patch")?; // if uptodate if proposal_tip.eq(&local_branch_tip) { @@ -101,7 +101,7 @@ pub async fn launch() -> Result<()> { check_clean(&git_repo)?; let applied = git_repo .apply_patch_chain(&branch_name, most_recent_proposal_patch_chain) - .context("cannot apply patch chain")?; + .context("failed to apply patch chain")?; println!("applied {} new commits", applied.len(),); } // if parent commit doesnt exist @@ -123,7 +123,7 @@ pub async fn launch() -> Result<()> { git_repo.create_branch_at_commit(&branch_name, &proposal_base_commit.to_string())?; let applied = git_repo .apply_patch_chain(&branch_name, most_recent_proposal_patch_chain) - .context("cannot apply patch chain")?; + .context("failed to apply patch chain")?; println!( "pulled new version of proposal ({} ahead {} behind '{main_branch_name}'), replacing old version ({} ahead {} behind '{main_branch_name}')", @@ -138,7 +138,7 @@ pub async fn launch() -> Result<()> { else if git_repo.ancestor_of(&local_branch_tip, &proposal_tip)? { let (local_ahead_of_proposal, _) = git_repo .get_commits_ahead_behind(&proposal_tip, &local_branch_tip) - .context("cannot get commits ahead behind for propsal_top and local_branch_tip")?; + .context("failed to get commits ahead behind for propsal_top and local_branch_tip")?; println!( "local proposal branch exists with {} unpublished commits on top of the most up-to-date version of the proposal", local_ahead_of_proposal.len() @@ -196,7 +196,7 @@ pub async fn launch() -> Result<()> { fn check_clean(git_repo: &Repo) -> Result<()> { if git_repo.has_outstanding_changes()? { bail!( - "cannot pull proposal branch when repository is not clean. discard or stash (un)staged changes and try again." + "failed to pull proposal branch when repository is not clean. discard or stash (un)staged changes and try again." ); } Ok(()) diff --git a/src/bin/ngit/sub_commands/push.rs b/src/bin/ngit/sub_commands/push.rs index aaf1009..89b2364 100644 --- a/src/bin/ngit/sub_commands/push.rs +++ b/src/bin/ngit/sub_commands/push.rs @@ -29,7 +29,7 @@ pub struct SubCommandArgs { #[allow(clippy::too_many_lines)] pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { - let git_repo = Repo::discover().context("cannot find a git repository")?; + let git_repo = Repo::discover().context("failed to find a git repository")?; let git_repo_path = git_repo.get_path()?; let (main_or_master_branch_name, _) = git_repo @@ -42,7 +42,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { let branch_name = git_repo .get_checked_out_branch_name() - .context("cannot get checked out branch name")?; + .context("failed to get checked out branch name")?; if branch_name == main_or_master_branch_name { bail!("checkout a branch associated with a proposal first") @@ -70,7 +70,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { is_event_proposal_root_for_branch(e, &branch_name, &logged_in_public_key) .unwrap_or(false) }) - .context("cannot find proposal that matches the current branch name")? + .context("failed to find proposal that matches the current branch name")? .clone(); let commit_events = @@ -78,7 +78,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { .await?; let most_recent_proposal_patch_chain = get_most_recent_patch_with_ancestors(commit_events) - .context("cannot get most recent patch for proposal")?; + .context("failed to get most recent patch for proposal")?; let branch_tip = git_repo.get_tip_of_branch(&branch_name)?; @@ -191,7 +191,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { &[], ) .await - .context("cannot make patch event from commit")?, + .context("failed to make patch event from commit")?, ); } println!("pushing {} commits", ahead.len()); diff --git a/src/bin/ngit/sub_commands/send.rs b/src/bin/ngit/sub_commands/send.rs index 114a021..1965875 100644 --- a/src/bin/ngit/sub_commands/send.rs +++ b/src/bin/ngit/sub_commands/send.rs @@ -45,7 +45,7 @@ pub struct SubCommandArgs { #[allow(clippy::too_many_lines)] pub async fn launch(cli_args: &Cli, args: &SubCommandArgs, no_fetch: bool) -> Result<()> { - let git_repo = Repo::discover().context("cannot find a git repository")?; + let git_repo = Repo::discover().context("failed to find a git repository")?; let git_repo_path = git_repo.get_path()?; let (main_branch_name, main_tip) = git_repo @@ -83,7 +83,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs, no_fetch: bool) -> Re } else { git_repo .parse_starting_commits(&args.since_or_range) - .context("cannot parse specified starting commit or range")? + .context("failed to parse specified starting commit or range")? } }; -- cgit v1.2.3