mirror of
https://github.com/martinvonz/jj.git
synced 2025-05-14 11:44:27 +00:00
cli: remove less-frequently-used user_error factories
This commit is contained in:
parent
2523dc188c
commit
b77a110e8a
@ -126,23 +126,6 @@ pub fn user_error_with_message(
|
|||||||
user_error(ErrorWithMessage::new(message, source))
|
user_error(ErrorWithMessage::new(message, source))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn user_error_with_message_and_hint(
|
|
||||||
message: impl Into<String>,
|
|
||||||
hint: impl Into<String>,
|
|
||||||
source: impl Into<Box<dyn error::Error + Send + Sync>>,
|
|
||||||
) -> CommandError {
|
|
||||||
user_error_with_message(message, source).hinted(hint)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn user_error_with_hint_opt(
|
|
||||||
err: impl Into<Box<dyn error::Error + Send + Sync>>,
|
|
||||||
hint: Option<String>,
|
|
||||||
) -> CommandError {
|
|
||||||
let mut err = CommandError::new(CommandErrorKind::User, err);
|
|
||||||
err.extend_hints(hint);
|
|
||||||
err
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn config_error(err: impl Into<Box<dyn error::Error + Send + Sync>>) -> CommandError {
|
pub fn config_error(err: impl Into<Box<dyn error::Error + Send + Sync>>) -> CommandError {
|
||||||
CommandError::new(CommandErrorKind::Config, err)
|
CommandError::new(CommandErrorKind::Config, err)
|
||||||
}
|
}
|
||||||
@ -278,12 +261,12 @@ impl From<OpsetEvaluationError> for CommandError {
|
|||||||
impl From<SnapshotError> for CommandError {
|
impl From<SnapshotError> for CommandError {
|
||||||
fn from(err: SnapshotError) -> Self {
|
fn from(err: SnapshotError) -> Self {
|
||||||
match err {
|
match err {
|
||||||
SnapshotError::NewFileTooLarge { .. } => user_error_with_message_and_hint(
|
SnapshotError::NewFileTooLarge { .. } => {
|
||||||
"Failed to snapshot the working copy",
|
user_error_with_message("Failed to snapshot the working copy", err).hinted(
|
||||||
r#"Increase the value of the `snapshot.max-new-file-size` config option if you
|
r#"Increase the value of the `snapshot.max-new-file-size` config option if you
|
||||||
want this file to be snapshotted. Otherwise add it to your `.gitignore` file."#,
|
want this file to be snapshotted. Otherwise add it to your `.gitignore` file."#,
|
||||||
err,
|
)
|
||||||
),
|
}
|
||||||
err => internal_error_with_message("Failed to snapshot the working copy", err),
|
err => internal_error_with_message("Failed to snapshot the working copy", err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -364,10 +347,10 @@ repository contents."
|
|||||||
GitImportError::InternalGitError(_) => None,
|
GitImportError::InternalGitError(_) => None,
|
||||||
GitImportError::UnexpectedBackend => None,
|
GitImportError::UnexpectedBackend => None,
|
||||||
};
|
};
|
||||||
user_error_with_hint_opt(
|
let mut cmd_err =
|
||||||
ErrorWithMessage::new("Failed to import refs from underlying Git repo", err),
|
user_error_with_message("Failed to import refs from underlying Git repo", err);
|
||||||
hint,
|
cmd_err.extend_hints(hint);
|
||||||
)
|
cmd_err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -415,7 +398,9 @@ impl From<RevsetParseError> for CommandError {
|
|||||||
} => format_similarity_hint(candidates),
|
} => format_similarity_hint(candidates),
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
user_error_with_hint_opt(revset_util::format_parse_error(&err), hint)
|
let mut cmd_err = user_error(revset_util::format_parse_error(&err));
|
||||||
|
cmd_err.extend_hints(hint);
|
||||||
|
cmd_err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -432,7 +417,9 @@ impl From<RevsetResolutionError> for CommandError {
|
|||||||
| RevsetResolutionError::AmbiguousChangeIdPrefix(_)
|
| RevsetResolutionError::AmbiguousChangeIdPrefix(_)
|
||||||
| RevsetResolutionError::StoreError(_) => None,
|
| RevsetResolutionError::StoreError(_) => None,
|
||||||
};
|
};
|
||||||
user_error_with_hint_opt(err, hint)
|
let mut cmd_err = user_error(err);
|
||||||
|
cmd_err.extend_hints(hint);
|
||||||
|
cmd_err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -458,7 +445,9 @@ impl From<TemplateParseError> for CommandError {
|
|||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
user_error_with_hint_opt(format!("Failed to parse template: {message}"), hint)
|
let mut cmd_err = user_error(format!("Failed to parse template: {message}"));
|
||||||
|
cmd_err.extend_hints(hint);
|
||||||
|
cmd_err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,8 +45,7 @@ use crate::cli_util::{
|
|||||||
start_repo_transaction, CommandHelper, RevisionArg, WorkspaceCommandHelper,
|
start_repo_transaction, CommandHelper, RevisionArg, WorkspaceCommandHelper,
|
||||||
};
|
};
|
||||||
use crate::command_error::{
|
use crate::command_error::{
|
||||||
user_error, user_error_with_hint, user_error_with_hint_opt, user_error_with_message,
|
user_error, user_error_with_hint, user_error_with_message, CommandError,
|
||||||
CommandError,
|
|
||||||
};
|
};
|
||||||
use crate::git_util::{
|
use crate::git_util::{
|
||||||
get_git_repo, is_colocated_git_workspace, print_failed_git_export, print_git_import_stats,
|
get_git_repo, is_colocated_git_workspace, print_failed_git_export, print_git_import_stats,
|
||||||
@ -1107,7 +1106,9 @@ impl RejectedBranchUpdateReason {
|
|||||||
impl From<RejectedBranchUpdateReason> for CommandError {
|
impl From<RejectedBranchUpdateReason> for CommandError {
|
||||||
fn from(reason: RejectedBranchUpdateReason) -> Self {
|
fn from(reason: RejectedBranchUpdateReason) -> Self {
|
||||||
let RejectedBranchUpdateReason { message, hint } = reason;
|
let RejectedBranchUpdateReason { message, hint } = reason;
|
||||||
user_error_with_hint_opt(message, hint)
|
let mut cmd_err = user_error(message);
|
||||||
|
cmd_err.extend_hints(hint);
|
||||||
|
cmd_err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user