From b37e1167192aecfbef95556107f75df4dd7dd07b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Tue, 18 Apr 2023 01:05:10 -0700 Subject: [PATCH] fix(error): export orogene cmd error enum --- src/commands/remove.rs | 22 +++------------------- src/error.rs | 18 ++++++++++++++++++ src/lib.rs | 3 +++ 3 files changed, 24 insertions(+), 19 deletions(-) create mode 100644 src/error.rs diff --git a/src/commands/remove.rs b/src/commands/remove.rs index e133c8e6..fe7fcce1 100644 --- a/src/commands/remove.rs +++ b/src/commands/remove.rs @@ -1,28 +1,12 @@ use async_trait::async_trait; use clap::Args; -use miette::{Diagnostic, IntoDiagnostic, Result}; +use miette::{IntoDiagnostic, Result}; use nassun::PackageSpec; use oro_pretty_json::Formatted; -use thiserror::Error; use crate::apply_args::ApplyArgs; use crate::commands::OroCommand; - -#[derive(Debug, Error, Diagnostic)] -enum RemoveCmdError { - /// Invalid package name. Only package names should be passed to `oro - /// remove`, but you passed either a package specifier or an invalid - /// package name. - /// - /// Try passing the package name as it appears in your package.json. - #[error("{0} is not a valid package name. Only package names should be passed to `oro remove`, but you passed either a non-NPM package specifier or an invalid package name.")] - #[diagnostic( - code(oro::remove::invalid_package_name), - url(docsrs), - help("Use the package name as it appears in your package.json instead.") - )] - InvalidPackageName(String), -} +use crate::OroError; /// Removes one or more dependencies from the target package. #[derive(Debug, Args)] @@ -57,7 +41,7 @@ impl OroCommand for RemoveCmd { } count += self.remove_from_manifest(&mut manifest, &spec_name); } else { - return Err(RemoveCmdError::InvalidPackageName(name.clone()).into()); + return Err(OroError::InvalidPackageName(name.clone()).into()); } } diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 00000000..325e2f1c --- /dev/null +++ b/src/error.rs @@ -0,0 +1,18 @@ +use miette::Diagnostic; +use thiserror::Error; + +#[derive(Debug, Error, Diagnostic)] +pub enum OroError { + /// Invalid package name. Only package names should be passed to `oro + /// remove`, but you passed either a package specifier or an invalid + /// package name. + /// + /// Try passing the package name as it appears in your package.json. + #[error("{0} is not a valid package name. Only package names should be passed to `oro remove`, but you passed either a non-NPM package specifier or an invalid package name.")] + #[diagnostic( + code(oro::remove::invalid_package_name), + url(docsrs), + help("Use the package name as it appears in your package.json instead.") + )] + InvalidPackageName(String), +} diff --git a/src/lib.rs b/src/lib.rs index 10a6bdda..ad84e2e3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -58,8 +58,11 @@ use url::Url; use commands::OroCommand; +pub use error::OroError; + mod apply_args; mod commands; +mod error; mod nassun_args; const MAX_RETAINED_LOGS: usize = 5;