From 91ff1fdd1e37b7339e5d240ecd9efd913711b32d Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Fri, 29 Mar 2024 20:07:26 +0900 Subject: [PATCH] cli: extract CommandError::with_message() constructor --- cli/src/command_error.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/cli/src/command_error.rs b/cli/src/command_error.rs index 3c9eb4d9b..983a44c6f 100644 --- a/cli/src/command_error.rs +++ b/cli/src/command_error.rs @@ -72,6 +72,14 @@ impl CommandError { } } + pub fn with_message( + kind: CommandErrorKind, + message: impl Into, + source: impl Into>, + ) -> Self { + Self::new(kind, ErrorWithMessage::new(message, source)) + } + /// Returns error with the given plain-text `hint` attached. pub fn hinted(mut self, hint: impl Into) -> Self { self.add_hint(hint); @@ -146,7 +154,7 @@ pub fn user_error_with_message( message: impl Into, source: impl Into>, ) -> CommandError { - user_error(ErrorWithMessage::new(message, source)) + CommandError::with_message(CommandErrorKind::User, message, source) } pub fn config_error(err: impl Into>) -> CommandError { @@ -157,7 +165,7 @@ pub fn config_error_with_message( message: impl Into, source: impl Into>, ) -> CommandError { - config_error(ErrorWithMessage::new(message, source)) + CommandError::with_message(CommandErrorKind::Config, message, source) } pub fn cli_error(err: impl Into>) -> CommandError { @@ -172,7 +180,7 @@ pub fn internal_error_with_message( message: impl Into, source: impl Into>, ) -> CommandError { - internal_error(ErrorWithMessage::new(message, source)) + CommandError::with_message(CommandErrorKind::Internal, message, source) } fn format_similarity_hint>(candidates: &[S]) -> Option {