Skip to content

Commit 3553d83

Browse files
authored
updating error-stack (#22)
1 parent 5e148bb commit 3553d83

File tree

5 files changed

+36
-60
lines changed

5 files changed

+36
-60
lines changed

Cargo.lock

Lines changed: 15 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ debug = true
99
[dependencies]
1010
clap = { version = "4.2.1", features = ["derive"] }
1111
clap_derive = "4.2.0"
12-
error-stack = "0.3.1"
12+
error-stack = "0.4.1"
1313
glob-match = "0.2.1"
1414
ignore = "0.4.20"
15-
itertools = "0.10.5"
15+
itertools = "0.12.1"
1616
path-clean = "1.0.1"
1717
rayon = "1.7.0"
1818
regex = "1.7.3"

src/error_stack_ext.rs

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/main.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use error_stack_ext::IntoContext;
21
use ownership::Ownership;
32

43
use crate::project::Project;
@@ -13,7 +12,6 @@ use std::{
1312
};
1413

1514
mod config;
16-
mod error_stack_ext;
1715
mod ownership;
1816
mod project;
1917

@@ -50,7 +48,7 @@ struct Args {
5048

5149
impl Args {
5250
fn absolute_project_root(&self) -> Result<PathBuf, Error> {
53-
self.project_root.canonicalize().into_context(Error::Io)
51+
self.project_root.canonicalize().change_context(Error::Io)
5452
}
5553

5654
fn absolute_config_path(&self) -> Result<PathBuf, Error> {
@@ -98,21 +96,21 @@ fn cli() -> Result<(), Error> {
9896
let project_root = args.absolute_project_root()?;
9997

10098
let config_file = File::open(&config_path)
101-
.into_context(Error::Io)
99+
.change_context(Error::Io)
102100
.attach_printable(format!("Can't open config file: {}", config_path.to_string_lossy()))?;
103101

104-
let config = serde_yaml::from_reader(config_file).into_context(Error::Io)?;
102+
let config = serde_yaml::from_reader(config_file).change_context(Error::Io)?;
105103

106104
let ownership = Ownership::build(Project::build(&project_root, &codeowners_file_path, &config).change_context(Error::Io)?);
107105

108106
match args.command {
109-
Command::Validate => ownership.validate().into_context(Error::ValidationFailed)?,
107+
Command::Validate => ownership.validate().change_context(Error::ValidationFailed)?,
110108
Command::Generate => {
111-
std::fs::write(codeowners_file_path, ownership.generate_file()).into_context(Error::Io)?;
109+
std::fs::write(codeowners_file_path, ownership.generate_file()).change_context(Error::Io)?;
112110
}
113111
Command::GenerateAndValidate => {
114-
std::fs::write(codeowners_file_path, ownership.generate_file()).into_context(Error::Io)?;
115-
ownership.validate().into_context(Error::ValidationFailed)?
112+
std::fs::write(codeowners_file_path, ownership.generate_file()).change_context(Error::Io)?;
113+
ownership.validate().change_context(Error::ValidationFailed)?
116114
}
117115
}
118116

src/project.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ use std::{
66
path::{Path, PathBuf},
77
};
88

9-
use error_stack::{Context, Result};
9+
use error_stack::{Context, Result, ResultExt};
1010

1111
use ignore::WalkBuilder;
1212
use rayon::prelude::{IntoParallelIterator, ParallelIterator};
1313
use regex::Regex;
1414
use tracing::{info, instrument};
1515

16-
use crate::{config::Config, error_stack_ext::IntoContext};
16+
use crate::config::Config;
1717
use glob_match::glob_match;
1818

1919
pub struct Project {
@@ -163,10 +163,10 @@ impl Project {
163163
let walkdir = builder.build();
164164

165165
for entry in walkdir {
166-
let entry = entry.into_context(Error::Io)?;
166+
let entry = entry.change_context(Error::Io)?;
167167

168168
let absolute_path = entry.path();
169-
let relative_path = absolute_path.strip_prefix(base_path).into_context(Error::Io)?.to_owned();
169+
let relative_path = absolute_path.strip_prefix(base_path).change_context(Error::Io)?.to_owned();
170170

171171
if entry.file_type().unwrap().is_dir() {
172172
if relative_path.parent() == Some(Path::new(&config.vendored_gems_path)) {
@@ -205,7 +205,7 @@ impl Project {
205205
}
206206

207207
if file_name.eq_ignore_ascii_case(".codeowner") {
208-
let owner = std::fs::read_to_string(absolute_path).into_context(Error::Io)?;
208+
let owner = std::fs::read_to_string(absolute_path).change_context(Error::Io)?;
209209
let owner = owner.trim().to_owned();
210210

211211
let relative_path = relative_path.to_owned();
@@ -216,8 +216,8 @@ impl Project {
216216
}
217217

218218
if matches_globs(&relative_path, &config.team_file_glob) {
219-
let file = File::open(absolute_path).into_context(Error::Io)?;
220-
let deserializer: deserializers::Team = serde_yaml::from_reader(file).into_context(Error::SerdeYaml)?;
219+
let file = File::open(absolute_path).change_context(Error::Io)?;
220+
let deserializer: deserializers::Team = serde_yaml::from_reader(file).change_context(Error::SerdeYaml)?;
221221

222222
teams.push(Team {
223223
path: absolute_path.to_owned(),
@@ -243,7 +243,7 @@ impl Project {
243243
);
244244

245245
let codeowners_file: String = if codeowners_file_path.exists() {
246-
std::fs::read_to_string(codeowners_file_path).into_context(Error::Io)?
246+
std::fs::read_to_string(codeowners_file_path).change_context(Error::Io)?
247247
} else {
248248
"".to_owned()
249249
};
@@ -326,15 +326,15 @@ fn owned_files(owned_file_paths: Vec<PathBuf>) -> Vec<ProjectFile> {
326326
}
327327

328328
fn ruby_package_owner(path: &Path) -> Result<Option<String>, Error> {
329-
let file = File::open(path).into_context(Error::Io)?;
330-
let deserializer: deserializers::RubyPackage = serde_yaml::from_reader(file).into_context(Error::SerdeYaml)?;
329+
let file = File::open(path).change_context(Error::Io)?;
330+
let deserializer: deserializers::RubyPackage = serde_yaml::from_reader(file).change_context(Error::SerdeYaml)?;
331331

332332
Ok(deserializer.owner)
333333
}
334334

335335
fn javascript_package_owner(path: &Path) -> Result<Option<String>, Error> {
336-
let file = File::open(path).into_context(Error::Io)?;
337-
let deserializer: deserializers::JavascriptPackage = serde_json::from_reader(file).into_context(Error::SerdeJson)?;
336+
let file = File::open(path).change_context(Error::Io)?;
337+
let deserializer: deserializers::JavascriptPackage = serde_json::from_reader(file).change_context(Error::SerdeJson)?;
338338

339339
Ok(deserializer.metadata.and_then(|metadata| metadata.owner))
340340
}

0 commit comments

Comments
 (0)