diff --git a/Cargo.lock b/Cargo.lock index 769d8d7..d16f578 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,21 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "addr2line" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a76fd60b23679b7d19bd066031410fb7e458ccc5e958eb5c325888ce4baedc97" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + [[package]] name = "aho-corasick" version = "0.7.20" @@ -72,6 +87,21 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "backtrace" +version = "0.3.67" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "233d376d6d185f2a3093e58f283f60f880315b6c60075b01f36b3b85154564ca" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -160,6 +190,7 @@ dependencies = [ "assert_cmd", "clap", "clap_derive", + "color-eyre", "glob-match", "itertools", "jwalk", @@ -173,6 +204,33 @@ dependencies = [ "tracing-subscriber", ] +[[package]] +name = "color-eyre" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a667583cca8c4f8436db8de46ea8233c42a7d9ae424a82d338f2e4675229204" +dependencies = [ + "backtrace", + "color-spantrace", + "eyre", + "indenter", + "once_cell", + "owo-colors", + "tracing-error", +] + +[[package]] +name = "color-spantrace" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ba75b3d9449ecdccb27ecbc479fdc0b87fa2dd43d2f8298f9bf0e59aacc8dce" +dependencies = [ + "once_cell", + "owo-colors", + "tracing-core", + "tracing-error", +] + [[package]] name = "concolor-override" version = "1.0.0" @@ -304,6 +362,16 @@ dependencies = [ "libc", ] +[[package]] +name = "eyre" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c2b6b5a29c02cdc822728b7d7b8ae1bab3e3b05d44522770ddd49722eeac7eb" +dependencies = [ + "indenter", + "once_cell", +] + [[package]] name = "fsio" version = "0.1.3" @@ -319,6 +387,12 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "gimli" +version = "0.27.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad0a93d233ebf96623465aad4046a8d3aa4da22d4f4beba5388838c8a434bbb4" + [[package]] name = "glob-match" version = "0.2.1" @@ -352,6 +426,12 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" +[[package]] +name = "indenter" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" + [[package]] name = "indexmap" version = "1.9.3" @@ -461,6 +541,15 @@ dependencies = [ "autocfg", ] +[[package]] +name = "miniz_oxide" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b275950c28b37e794e8c55d88aeb5e139d0ce23fdbbeda68f8d7174abdf9e8fa" +dependencies = [ + "adler", +] + [[package]] name = "nias" version = "0.5.0" @@ -487,6 +576,15 @@ dependencies = [ "libc", ] +[[package]] +name = "object" +version = "0.30.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea86265d3d3dcb6a27fc51bd29a4bf387fae9d2986b823079d4986af253eb439" +dependencies = [ + "memchr", +] + [[package]] name = "once_cell" version = "1.17.1" @@ -499,6 +597,12 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" +[[package]] +name = "owo-colors" +version = "3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" + [[package]] name = "path-clean" version = "1.0.1" @@ -605,6 +709,12 @@ version = "0.6.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" +[[package]] +name = "rustc-demangle" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4a36c42d1873f9a77c53bde094f9664d9891bc604a45b4798fd2c389ed12e5b" + [[package]] name = "rustix" version = "0.37.5" @@ -777,6 +887,16 @@ dependencies = [ "valuable", ] +[[package]] +name = "tracing-error" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d686ec1c0f384b1277f097b2f279a2ecc11afe8c133c1aabf036a27cb4cd206e" +dependencies = [ + "tracing", + "tracing-subscriber", +] + [[package]] name = "tracing-log" version = "0.1.3" diff --git a/Cargo.toml b/Cargo.toml index 56b7814..e4067a8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,9 +3,14 @@ name = "codeowners" version = "0.1.0" edition = "2021" +[profile.release] +debug = true + [dependencies] clap = { version = "4.2.1", features = ["derive"] } clap_derive = "4.2.0" +color-eyre = "0.6.2" + glob-match = "0.2.1" itertools = "0.10.5" jwalk = "0.8.1" diff --git a/src/main.rs b/src/main.rs index d53d563..3c4c69d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,11 +1,10 @@ +use color_eyre::{eyre::Context, Result}; use ownership::{Ownership, ValidationErrors}; -use tracing::debug; use crate::project::Project; use clap::{Parser, Subcommand}; use path_clean::PathClean; use std::{ - error::Error, fs::File, path::{Path, PathBuf}, process, @@ -47,44 +46,42 @@ struct Args { } impl Args { - fn absolute_project_root(&self) -> Result { - self.project_root.canonicalize() + fn absolute_project_root(&self) -> Result { + self.project_root + .canonicalize() + .with_context(|| format!("Can't canonizalize {}", self.project_root.to_string_lossy())) } - fn absolute_config_path(&self) -> Result { + fn absolute_config_path(&self) -> Result { Ok(self.absolute_path(&self.config_path)?.clean()) } - fn absolute_codeowners_path(&self) -> Result { + fn absolute_codeowners_path(&self) -> Result { Ok(self.absolute_path(&self.codeowners_file_path)?.clean()) } - fn absolute_path(&self, path: &Path) -> Result { + fn absolute_path(&self, path: &Path) -> Result { Ok(self.absolute_project_root()?.join(path)) } } -fn main() -> Result<(), Box> { +fn main() -> Result<()> { + color_eyre::install()?; install_logger(); print_validation_errors_to_stdout(cli())?; Ok(()) } -fn cli() -> Result<(), Box> { +fn cli() -> Result<()> { let args = Args::parse(); let config_path = args.absolute_config_path()?; let codeowners_file_path = args.absolute_codeowners_path()?; let project_root = args.absolute_project_root()?; - debug!( - config_path = &config_path.to_str(), - codeowners_file_path = &codeowners_file_path.to_str(), - project_root = &project_root.to_str(), - ); - - let config = serde_yaml::from_reader(File::open(config_path)?)?; + let config = + serde_yaml::from_reader(File::open(&config_path).with_context(|| format!("Can't open {}", config_path.to_string_lossy()))?)?; let ownership = Ownership::build(Project::build(&project_root, &codeowners_file_path, &config)?); let command = args.command; @@ -102,7 +99,7 @@ fn cli() -> Result<(), Box> { Ok(()) } -fn print_validation_errors_to_stdout(result: Result<(), Box>) -> Result<(), Box> { +fn print_validation_errors_to_stdout(result: Result<()>) -> Result<()> { if let Err(error) = result { if let Some(validation_errors) = error.downcast_ref::() { println!("{}", validation_errors); diff --git a/src/project.rs b/src/project.rs index aa06929..d4db98e 100644 --- a/src/project.rs +++ b/src/project.rs @@ -1,11 +1,11 @@ use std::{ collections::HashMap, - error::Error, fs::File, io::BufRead, path::{Path, PathBuf}, }; +use color_eyre::Result; use jwalk::WalkDir; use rayon::prelude::{IntoParallelIterator, ParallelIterator}; use regex::Regex; @@ -111,7 +111,7 @@ mod deserializers { impl Project { #[instrument(level = "debug", skip_all)] - pub fn build(base_path: &Path, codeowners_file_path: &Path, config: &Config) -> Result> { + pub fn build(base_path: &Path, codeowners_file_path: &Path, config: &Config) -> Result { debug!("scanning project ({})", base_path.to_string_lossy()); let mut owned_file_paths: Vec = Vec::new(); @@ -272,7 +272,7 @@ fn owned_files(owned_file_paths: Vec) -> Vec { .collect() } -fn package_owner(path: &Path) -> Result, Box> { +fn package_owner(path: &Path) -> Result> { let deserializer: deserializers::Package = serde_yaml::from_reader(File::open(path)?)?; if let Some(metadata) = deserializer.metadata {