diff --git a/crates/cli/src/lib.rs b/crates/cli/src/lib.rs index 2ff15cbc8..860f33662 100644 --- a/crates/cli/src/lib.rs +++ b/crates/cli/src/lib.rs @@ -26,28 +26,43 @@ async fn run_commands(cli: Cli) -> Result<()> { match &cli.subcommand { Subcommands::Init => { // init command throws an error if package.json file exist. - PackageJson::init(&package_json_path)?; + PackageJson::init(&package_json_path).with_context(|| { + format!("Failed to initialize package.json at path {:?}", &package_json_path) + })?; } Subcommands::Add(args) => { - let mut package_manager = PackageManager::new(package_json_path)?; + let mut package_manager = + PackageManager::new(&package_json_path).with_context(|| { + format!("Failed to read package.json at path {:?}", &package_json_path) + })?; // TODO if a package already exists in another dependency group, we don't remove // the existing entry. package_manager .add(&args.package, args.get_dependency_group(), args.save_exact) - .await?; + .await + .with_context(|| format!("Failed to add package {}", &args.package))?; } Subcommands::Install(args) => { - let mut package_manager = PackageManager::new(package_json_path)?; - package_manager.install(args.dev, !args.no_optional).await?; + let mut package_manager = + PackageManager::new(&package_json_path).with_context(|| { + format!("Failed to read package.json at path {:?}", &package_json_path) + })?; + package_manager.install(args.dev, !args.no_optional).await.with_context(|| { + format!("Failed to install packages on {:?}", package_json_path) + })?; } Subcommands::Test => { - let package_json = PackageJson::from_path(&package_json_path)?; + let package_json = PackageJson::from_path(&package_json_path).with_context(|| { + format!("Failed to read package.json at path {:?}", &package_json_path) + })?; if let Some(script) = package_json.get_script("test", false)? { execute_shell(script)?; } } Subcommands::Run(args) => { - let package_json = PackageJson::from_path(&package_json_path)?; + let package_json = PackageJson::from_path(&package_json_path).with_context(|| { + format!("Failed to read package.json at path {:?}", &package_json_path) + })?; if let Some(script) = package_json.get_script(&args.command, args.if_present)? { execute_shell(script)?; } @@ -57,7 +72,9 @@ async fn run_commands(cli: Cli) -> Result<()> { // object. If no start property is specified on the scripts object, it will attempt to // run node server.js as a default, failing if neither are present. // The intended usage of the property is to specify a command that starts your program. - let package_json = PackageJson::from_path(&package_json_path)?; + let package_json = PackageJson::from_path(&package_json_path).with_context(|| { + format!("Failed to read package.json at path {:?}", &package_json_path) + })?; if let Some(script) = package_json.get_script("start", true)? { execute_shell(script)?; } else { @@ -84,7 +101,6 @@ mod tests { env::set_current_dir(parent_folder.path()).unwrap(); let cli = Cli::parse_from(["", "init"]); run_commands(cli).await.unwrap(); - assert!(parent_folder.path().join("package.json").exists()); env::set_current_dir(¤t_directory).unwrap(); } diff --git a/crates/executor/src/lib.rs b/crates/executor/src/lib.rs index 57a163e9e..1636d6176 100644 --- a/crates/executor/src/lib.rs +++ b/crates/executor/src/lib.rs @@ -5,7 +5,7 @@ use thiserror::Error; #[derive(Error, Debug)] #[non_exhaustive] pub enum ExecutorError { - #[error("io error: {0}")] + #[error("io error")] Io(#[from] std::io::Error), } diff --git a/crates/lockfile/src/lib.rs b/crates/lockfile/src/lib.rs index 18639691c..54e446113 100644 --- a/crates/lockfile/src/lib.rs +++ b/crates/lockfile/src/lib.rs @@ -15,9 +15,9 @@ use crate::package::LockfilePackage; #[derive(Error, Debug)] #[non_exhaustive] pub enum LockfileError { - #[error("filesystem error: `{0}`")] + #[error("filesystem error")] FileSystem(#[from] std::io::Error), - #[error("serialization error: `{0}")] + #[error("serialization error")] Serialization(#[from] serde_yaml::Error), } diff --git a/crates/package_json/src/error.rs b/crates/package_json/src/error.rs index 846a073d4..f100b7aa6 100644 --- a/crates/package_json/src/error.rs +++ b/crates/package_json/src/error.rs @@ -3,9 +3,9 @@ use thiserror::Error; #[derive(Error, Debug)] #[non_exhaustive] pub enum PackageJsonError { - #[error("serialization failed: {0}")] + #[error("serialization failed with {0}")] Serialization(#[from] serde_json::Error), - #[error("io error: `{0}`")] + #[error("io error")] Io(#[from] std::io::Error), #[error("package.json file already exists")] AlreadyExist, diff --git a/crates/package_manager/src/lib.rs b/crates/package_manager/src/lib.rs index 05137f19a..bcf250c85 100644 --- a/crates/package_manager/src/lib.rs +++ b/crates/package_manager/src/lib.rs @@ -12,11 +12,11 @@ pub mod install; #[derive(Error, Debug)] #[non_exhaustive] pub enum PackageManagerError { - #[error("tarball error: {0}")] + #[error("tarball error")] Tarball(#[from] pacquet_tarball::TarballError), - #[error("package.json error: {0}")] + #[error("package.json error")] PackageJson(#[from] pacquet_package_json::error::PackageJsonError), - #[error("registry error: {0}")] + #[error("registry error")] Registry(#[from] pacquet_registry::RegistryError), } diff --git a/crates/registry/src/lib.rs b/crates/registry/src/lib.rs index 208262423..ae10a851a 100644 --- a/crates/registry/src/lib.rs +++ b/crates/registry/src/lib.rs @@ -11,19 +11,19 @@ use crate::package::{Package, PackageVersion}; pub enum RegistryError { #[error("missing latest tag on {0}")] MissingLatestTag(String), - #[error("missing version {0} on package {0}")] + #[error("missing version {0} on package {1}")] MissingVersionRelease(String, String), #[error("network error while fetching {0}")] Network(#[from] reqwest::Error), - #[error("network middleware error")] + #[error("network middleware error with {0}")] NetworkMiddleware(#[from] reqwest_middleware::Error), - #[error("io error {0}")] + #[error("io error with {0}")] Io(#[from] std::io::Error), - #[error("serialization failed: {0}")] + #[error("serialization failed")] Serialization(String), - #[error("tarball error: {0}")] + #[error("tarball error with {0}")] Tarball(#[from] pacquet_tarball::TarballError), - #[error("package.json error: {0}")] + #[error("package.json error")] PackageJson(#[from] pacquet_package_json::error::PackageJsonError), }