Skip to content

Conversation

@perryqh
Copy link
Contributor

@perryqh perryqh commented May 4, 2025

Handle None or Error instead of panicking

@perryqh perryqh requested a review from Copilot May 4, 2025 01:51
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR removes several unwraps to gracefully handle None and error cases instead of panicking. Key changes include updating pattern matching in package file checks, refactoring functions to return Options instead of unwrapping parent paths, and replacing unwrap calls with error logging.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/project_builder.rs Replaced unwrap usage for parent paths and package owner retrieval with match statements.
src/project.rs Updated package_root and directory_root to return Options instead of unwrapping.
src/ownership/mapper/package_mapper.rs Updated package mapping to account for Option return values from package_root.
src/ownership/mapper/directory_mapper.rs Adjusted directory path handling by mapping Options to default strings when necessary.
src/cache/file.rs Removed unwrap from directory creation, silently ignoring errors now.

Comment on lines 94 to 103
let _ =fs::create_dir_all(&cache_dir);

Copy link

Copilot AI May 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider handling or logging errors from create_dir_all rather than silently ignoring them, as failed directory creation might affect file caching.

Suggested change
let _ =fs::create_dir_all(&cache_dir);
if let Err(e) = fs::create_dir_all(&cache_dir) {
eprintln!("Failed to create cache directory {}: {}", cache_dir.display(), e);
}

Copilot uses AI. Check for mistakes.
Comment on lines +125 to +128
if let (Some(current_root), Some(last_root)) = (package.package_root(), last_package.package_root()) {
if !current_root.starts_with(last_root) {
top_level_packages.push(package);
}
Copy link

Copilot AI May 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Review the handling of packages with no parent (i.e. when package_root() returns None) to ensure they are processed as intended or explicitly handled.

Suggested change
if let (Some(current_root), Some(last_root)) = (package.package_root(), last_package.package_root()) {
if !current_root.starts_with(last_root) {
top_level_packages.push(package);
}
match (package.package_root(), last_package.package_root()) {
(Some(current_root), Some(last_root)) if !current_root.starts_with(last_root) => {
top_level_packages.push(package);
}
(None, _) | (_, None) => {
// Explicitly handle packages with no parent
top_level_packages.push(package);
}
_ => {}

Copilot uses AI. Check for mistakes.
@perryqh perryqh force-pushed the ph/remove-unwraps branch from 16459e2 to 9013927 Compare May 4, 2025 01:58
@perryqh perryqh force-pushed the ph/remove-unwraps branch from 9013927 to 3cccb71 Compare May 4, 2025 02:15
@perryqh perryqh merged commit 4473bf5 into main May 12, 2025
8 checks passed
@perryqh perryqh deleted the ph/remove-unwraps branch September 9, 2025 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants