Skip to content

Commit

Permalink
fix(error): export orogene cmd error enum
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Apr 18, 2023
1 parent e563871 commit b37e116
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
22 changes: 3 additions & 19 deletions 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)]
Expand Down Expand Up @@ -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());
}
}

Expand Down
18 changes: 18 additions & 0 deletions 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),
}
3 changes: 3 additions & 0 deletions src/lib.rs
Expand Up @@ -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;
Expand Down

0 comments on commit b37e116

Please sign in to comment.