From b8bd50d8c36ce51c969778679e40c4a38e3af8bf Mon Sep 17 00:00:00 2001 From: simonsan <14062932+simonsan@users.noreply.github.com> Date: Wed, 30 Oct 2024 01:46:23 +0100 Subject: [PATCH] DRY constructors for RusticError Signed-off-by: simonsan <14062932+simonsan@users.noreply.github.com> --- crates/core/src/error.rs | 38 ++++---------------------------------- 1 file changed, 4 insertions(+), 34 deletions(-) diff --git a/crates/core/src/error.rs b/crates/core/src/error.rs index b32133e5..da5f018f 100644 --- a/crates/core/src/error.rs +++ b/crates/core/src/error.rs @@ -277,25 +277,10 @@ impl RusticError { /// Creates a new error with the given kind and guidance. pub fn with_source( kind: ErrorKind, - guidance: impl Into, + guidance: impl Into, source: impl Into>, ) -> Box { - Box::new(Self { - kind, - guidance: guidance.into().into(), - context: Cow::default(), - source: Some(source.into()), - error_code: None, - docs_url: None, - new_issue_url: None, - existing_issue_url: None, - severity: None, - status: None, - ask_report: false, - // `Backtrace::capture()` will check if backtrace has been enabled - // internally. It's zero cost if backtrace is disabled. - backtrace: Some(Backtrace::capture()), - }) + Self::new(kind, guidance).attach_source(source) } /// Checks if the error has a specific error code. @@ -312,25 +297,10 @@ impl RusticError { /// Creates a new error from a given error. pub fn from( - error: T, kind: ErrorKind, + error: T, ) -> Box { - Box::new(Self { - kind, - guidance: error.to_string().into(), - context: Cow::default(), - source: Some(Box::new(error)), - error_code: None, - docs_url: None, - new_issue_url: None, - existing_issue_url: None, - severity: None, - status: None, - ask_report: false, - // `Backtrace::capture()` will check if backtrace has been enabled - // internally. It's zero cost if backtrace is disabled. - backtrace: Some(Backtrace::capture()), - }) + Self::with_source(kind, error.to_string(), error) } }