diff --git a/Cargo.lock b/Cargo.lock index 1b3bdc2..82f29cb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,15 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "addr2line" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1" +dependencies = [ + "gimli", +] + [[package]] name = "adler2" version = "2.0.1" @@ -105,6 +114,30 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "backtrace" +version = "0.3.75" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6806a6321ec58106fea15becdad98371e28d92ccbc7c8f1b3b6dd724fe8f1002" +dependencies = [ + "addr2line", + "cfg-if", + "libc", + "miniz_oxide", + "object 0.36.7", + "rustc-demangle", + "windows-targets 0.52.6", +] + +[[package]] +name = "backtrace-ext" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "537beee3be4a18fb023b570f80e3ae28003db9167a751266b259926e25539d50" +dependencies = [ + "backtrace", +] + [[package]] name = "base64" version = "0.21.0" @@ -531,6 +564,12 @@ dependencies = [ "wasi 0.14.2+wasi-0.2.4", ] +[[package]] +name = "gimli" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" + [[package]] name = "h2" version = "0.3.17" @@ -720,6 +759,12 @@ version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12b6ee2129af8d4fb011108c73d99a1b83a85977f23b82460c0ae2e25bb4b57f" +[[package]] +name = "is_ci" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7655c9839580ee829dfacba1d1278c2b7883e50a277ff7541299489d6bdfdc45" + [[package]] name = "is_terminal_polyfill" version = "1.70.1" @@ -773,7 +818,7 @@ dependencies = [ "lz4", "maplit 0.1.6", "miette", - "object", + "object 0.23.0", "pest", "pest_derive", "regex", @@ -846,8 +891,16 @@ version = "7.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f98efec8807c63c752b5bd61f862c165c115b0a35685bdcfd9238c7aeb592b7" dependencies = [ + "backtrace", + "backtrace-ext", "cfg-if", "miette-derive", + "owo-colors", + "supports-color", + "supports-hyperlinks", + "supports-unicode", + "terminal_size", + "textwrap", "unicode-width", ] @@ -1000,6 +1053,15 @@ dependencies = [ "wasmparser", ] +[[package]] +name = "object" +version = "0.36.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87" +dependencies = [ + "memchr", +] + [[package]] name = "once_cell" version = "1.21.3" @@ -1078,6 +1140,12 @@ version = "6.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ceedf44fb00f2d1984b0bc98102627ce622e083e49a5bacdb3e514fa4238e267" +[[package]] +name = "owo-colors" +version = "4.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48dd4f4a2c8405440fd0462561f0e5806bd0f77e86f51c761481bdd4018b545e" + [[package]] name = "percent-encoding" version = "2.2.0" @@ -1173,12 +1241,12 @@ dependencies = [ name = "pkg6repo" version = "0.0.1-placeholder" dependencies = [ - "anyhow", "clap 4.5.41", "libips", + "miette", "serde", "serde_json", - "tempfile", + "thiserror 1.0.69", ] [[package]] @@ -1338,6 +1406,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "rustc-demangle" +version = "0.1.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "989e6739f80c4ad5b13e0fd7fe89531180375b18520cc8c82080e4dc4035b84f" + [[package]] name = "rustix" version = "1.0.8" @@ -1599,6 +1673,27 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "supports-color" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c64fc7232dd8d2e4ac5ce4ef302b1d81e0b80d055b9d77c7c4f51f6aa4c867d6" +dependencies = [ + "is_ci", +] + +[[package]] +name = "supports-hyperlinks" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "804f44ed3c63152de6a9f90acbea1a110441de43006ea51bcce8f436196a288b" + +[[package]] +name = "supports-unicode" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7401a30af6cb5818bb64852270bb722533397edcfc7344954a38f420819ece2" + [[package]] name = "syn" version = "1.0.109" @@ -1643,11 +1738,25 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "terminal_size" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45c6481c4829e4cc63825e62c49186a34538b7b2750b73b266581ffb612fb5ed" +dependencies = [ + "rustix", + "windows-sys 0.59.0", +] + [[package]] name = "textwrap" version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" +dependencies = [ + "unicode-linebreak", + "unicode-width", +] [[package]] name = "thiserror" @@ -1823,6 +1932,12 @@ version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" +[[package]] +name = "unicode-linebreak" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f" + [[package]] name = "unicode-normalization" version = "0.1.22" diff --git a/pkg6repo/Cargo.toml b/pkg6repo/Cargo.toml index 6f82d2c..dcae11b 100644 --- a/pkg6repo/Cargo.toml +++ b/pkg6repo/Cargo.toml @@ -13,10 +13,8 @@ keywords = ["packaging", "illumos"] [dependencies] clap = { version = "4.4", features = ["derive"] } -anyhow = "1.0" +miette = { version = "7.6.0", features = ["fancy"] } +thiserror = "1.0.50" libips = { path = "../libips" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" - -[dev-dependencies] -tempfile = "3.8" diff --git a/pkg6repo/src/e2e_tests.rs b/pkg6repo/src/e2e_tests.rs index a624e1c..9c6aebc 100644 --- a/pkg6repo/src/e2e_tests.rs +++ b/pkg6repo/src/e2e_tests.rs @@ -137,7 +137,7 @@ mod e2e_tests { ); // Add a publisher using pkg6repo - let result = run_pkg6repo(&["add-publisher", repo_path.to_str().unwrap(), "example.com"]); + let result = run_pkg6repo(&["add-publisher", "-s", repo_path.to_str().unwrap(), "example.com"]); assert!( result.is_ok(), "Failed to add publisher: {:?}", @@ -170,7 +170,7 @@ mod e2e_tests { ); // Add a publisher using pkg6repo - let result = run_pkg6repo(&["add-publisher", repo_path.to_str().unwrap(), "test"]); + let result = run_pkg6repo(&["add-publisher", "-s", repo_path.to_str().unwrap(), "test"]); assert!( result.is_ok(), "Failed to add publisher: {:?}", @@ -192,7 +192,7 @@ mod e2e_tests { ); // Check that the package was published - let result = run_pkg6repo(&["list", repo_path.to_str().unwrap()]); + let result = run_pkg6repo(&["list", "-s", repo_path.to_str().unwrap()]); assert!( result.is_ok(), "Failed to list packages: {:?}", @@ -227,7 +227,7 @@ mod e2e_tests { ); // Add a publisher using pkg6repo - let result = run_pkg6repo(&["add-publisher", repo_path.to_str().unwrap(), "test"]); + let result = run_pkg6repo(&["add-publisher", "-s", repo_path.to_str().unwrap(), "test"]); assert!( result.is_ok(), "Failed to add publisher: {:?}", @@ -249,7 +249,7 @@ mod e2e_tests { ); // Show package contents using pkg6repo - let result = run_pkg6repo(&["contents", repo_path.to_str().unwrap(), "example"]); + let result = run_pkg6repo(&["contents", "-s", repo_path.to_str().unwrap(), "example"]); assert!( result.is_ok(), "Failed to show package contents: {:?}", @@ -292,7 +292,7 @@ mod e2e_tests { ); // Add a publisher using pkg6repo - let result = run_pkg6repo(&["add-publisher", repo_path.to_str().unwrap(), "test"]); + let result = run_pkg6repo(&["add-publisher", "-s", repo_path.to_str().unwrap(), "test"]); assert!( result.is_ok(), "Failed to add publisher: {:?}", @@ -328,7 +328,7 @@ mod e2e_tests { ); // List packages using pkg6repo - let result = run_pkg6repo(&["list", repo_path.to_str().unwrap()]); + let result = run_pkg6repo(&["list", "-s", repo_path.to_str().unwrap()]); assert!( result.is_ok(), "Failed to list packages: {:?}", diff --git a/pkg6repo/src/error.rs b/pkg6repo/src/error.rs new file mode 100644 index 0000000..c0dd56c --- /dev/null +++ b/pkg6repo/src/error.rs @@ -0,0 +1,63 @@ +use libips::repository; +use miette::Diagnostic; +use thiserror::Error; + +/// Result type for pkg6repo operations +pub type Result = std::result::Result; + +/// Errors that can occur in pkg6repo operations +#[derive(Debug, Error, Diagnostic)] +pub enum Pkg6RepoError { + #[error("unsupported output format: {0}")] + #[diagnostic( + code(pkg6repo::unsupported_output_format), + help("Supported output formats: table, json, tsv") + )] + UnsupportedOutputFormat(String), + + #[error("invalid property=value format: {0}")] + #[diagnostic( + code(pkg6repo::invalid_property_value_format), + help("Property-value pairs must be in the format: property=value") + )] + InvalidPropertyValueFormat(String), + + #[error(transparent)] + #[diagnostic(transparent)] + RepositoryError(#[from] repository::RepositoryError), + + #[error("I/O error: {0}")] + #[diagnostic( + code(pkg6repo::io_error), + help("Check system resources and permissions") + )] + IoError(#[from] std::io::Error), + + #[error("JSON error: {0}")] + #[diagnostic( + code(pkg6repo::json_error), + help("Check the JSON format and try again") + )] + JsonError(#[from] serde_json::Error), + + #[error("other error: {0}")] + #[diagnostic( + code(pkg6repo::other_error), + help("See error message for details") + )] + Other(String), +} + +/// Convert a string to a Pkg6RepoError::Other +impl From for Pkg6RepoError { + fn from(s: String) -> Self { + Pkg6RepoError::Other(s) + } +} + +/// Convert a &str to a Pkg6RepoError::Other +impl From<&str> for Pkg6RepoError { + fn from(s: &str) -> Self { + Pkg6RepoError::Other(s.to_string()) + } +} \ No newline at end of file diff --git a/pkg6repo/src/main.rs b/pkg6repo/src/main.rs index 6431563..46b146d 100644 --- a/pkg6repo/src/main.rs +++ b/pkg6repo/src/main.rs @@ -1,4 +1,6 @@ -use anyhow::{anyhow, Result}; +mod error; +use error::{Pkg6RepoError, Result}; + use clap::{Parser, Subcommand}; use serde::Serialize; use std::convert::TryFrom; @@ -500,7 +502,7 @@ fn main() -> Result<()> { } } _ => { - return Err(anyhow!("Unsupported output format: {}", output_format)); + return Err(Pkg6RepoError::UnsupportedOutputFormat(output_format.to_string())); } } @@ -593,7 +595,7 @@ fn main() -> Result<()> { } } _ => { - return Err(anyhow!("Unsupported output format: {}", output_format)); + return Err(Pkg6RepoError::UnsupportedOutputFormat(output_format.to_string())); } } @@ -702,7 +704,7 @@ fn main() -> Result<()> { } } _ => { - return Err(anyhow!("Unsupported output format: {}", output_format)); + return Err(Pkg6RepoError::UnsupportedOutputFormat(output_format.to_string())); } } @@ -908,7 +910,7 @@ fn main() -> Result<()> { // Split the property=value string let parts: Vec<&str> = prop_val.split('=').collect(); if parts.len() != 2 { - return Err(anyhow!("Invalid property=value format: {}", prop_val)); + return Err(Pkg6RepoError::InvalidPropertyValueFormat(prop_val.to_string())); } let property = parts[0]; @@ -1027,11 +1029,11 @@ fn main() -> Result<()> { } } _ => { - return Err(anyhow!("Unsupported output format: {}", output_format)); + return Err(Pkg6RepoError::UnsupportedOutputFormat(output_format.to_string())); } } Ok(()) } } -} +} \ No newline at end of file