Skip to content

Commit f5694ac

Browse files
committed
refactor: improve error handling patterns and code quality
- replace map_err with inspect_err for side-effect error logging - simplify conditional unwrapping using if-let patterns - fix integer cast warning in status display calculation - update build command documentation to include clippy
1 parent 1fcd273 commit f5694ac

File tree

4 files changed

+10
-17
lines changed

4 files changed

+10
-17
lines changed

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
- Utility functions: git(args, working_dir) -> Result<String>, git_raw(args, working_dir) -> Result<Output>
2222
- Command modules: status.rs, add.rs, commit.rs (in src/commands/)
2323
- Core types: Hash (in src/types.rs)
24-
- Run `cargo build && cargo test` after code changes
24+
- Run `cargo build && cargo test && cargo clippy --all-targets --all-features -- -D warnings` after code changes
2525
- Make sure all examples are running
2626

2727
## Examples

examples/error_handling.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn main() -> Result<()> {
3131
demonstrate_file_operation_errors(&repo_path)?;
3232
demonstrate_git_command_errors(&repo_path)?;
3333
demonstrate_error_recovery_patterns(&repo_path)?;
34-
demonstrate_error_propagation_strategies(&base_path)?;
34+
demonstrate_error_propagation_strategies(base_path)?;
3535

3636
// Clean up
3737
println!("Cleaning up error handling examples...");
@@ -405,9 +405,8 @@ fn workflow_with_context(base_path: &str) -> Result<String> {
405405

406406
// Add context to errors
407407
let repo = Repository::init(&repo_path, false)
408-
.map_err(|e| {
408+
.inspect_err(|_e| {
409409
eprintln!("Context: Failed to initialize repository at {}", repo_path);
410-
e
411410
})?;
412411

413412
// Create file with context
@@ -419,16 +418,14 @@ fn workflow_with_context(base_path: &str) -> Result<String> {
419418

420419
// Add with context
421420
repo.add(&["context_file.txt"])
422-
.map_err(|e| {
421+
.inspect_err(|_e| {
423422
eprintln!("Context: Failed to stage context_file.txt");
424-
e
425423
})?;
426424

427425
// Commit with context
428426
let hash = repo.commit("Context workflow commit")
429-
.map_err(|e| {
427+
.inspect_err(|_e| {
430428
eprintln!("Context: Failed to create commit");
431-
e
432429
})?;
433430

434431
// Clean up

examples/staging_operations.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ fn display_status_changes(before: &rustic_git::GitStatus, after: &rustic_git::Gi
259259
let after_val = after_counts.get(status).unwrap_or(&0);
260260

261261
if before_val != after_val {
262-
println!(" {}: {} → {} ({:+})", status, before_val, after_val, *after_val as i32 - *before_val as i32);
262+
println!(" {}: {} → {} ({:+})", status, before_val, after_val, *after_val - *before_val);
263263
}
264264
}
265265
}

src/repository.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,7 @@ mod tests {
292292

293293
let result = Repository::init(test_path, false);
294294

295-
if result.is_ok() {
296-
let repo = result.unwrap();
295+
if let Ok(repo) = result {
297296
assert_eq!(repo.repo_path(), Path::new(test_path));
298297

299298
// Clean up
@@ -335,8 +334,7 @@ mod tests {
335334

336335
let result = Repository::init(test_path, false);
337336

338-
if result.is_ok() {
339-
let repo = result.unwrap();
337+
if let Ok(repo) = result {
340338
assert_eq!(repo.repo_path(), Path::new(test_path));
341339

342340
// Clean up
@@ -355,8 +353,7 @@ mod tests {
355353

356354
let result = Repository::init(test_path, false);
357355

358-
if result.is_ok() {
359-
let repo = result.unwrap();
356+
if let Ok(repo) = result {
360357
assert_eq!(repo.repo_path(), Path::new(test_path));
361358

362359
// Clean up
@@ -376,8 +373,7 @@ mod tests {
376373

377374
let result = Repository::init(&test_path, false);
378375

379-
if result.is_ok() {
380-
let repo = result.unwrap();
376+
if let Ok(repo) = result {
381377
assert_eq!(repo.repo_path(), Path::new(&test_path));
382378

383379
// Clean up

0 commit comments

Comments
 (0)