-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CLI completions #265
Add CLI completions #265
Conversation
✅ Deploy Preview for xvc canceled.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Key Issues
The PR review highlights the need for proper error handling to prevent silent failures, particularly with the use of unwrap()
and unwrap_or_else
, which can lead to panics or data corruption. Additionally, converting OsStr
to string using to_string_lossy()
may result in data loss with invalid Unicode sequences, and the code should implement functionality for setting a default pipeline instead of returning a Todo
error.
ref_platform.all().map(|all| { | ||
all.for_each(|reference| { | ||
if let Ok(reference) = reference { | ||
if let Some((_, name)) = reference.name().category_and_short_name() { | ||
refs.push(name.to_string()); | ||
} | ||
} | ||
}); | ||
Ok(refs) | ||
})? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🐛 Possible Bug
The map
closure silently ignores errors from reference
and category_and_short_name()
. This could hide important errors and lead to incomplete results. The closure should properly handle and propagate these errors using the ?
operator.
ref_platform.all().map(|all| { | |
all.for_each(|reference| { | |
if let Ok(reference) = reference { | |
if let Some((_, name)) = reference.name().category_and_short_name() { | |
refs.push(name.to_string()); | |
} | |
} | |
}); | |
Ok(refs) | |
})? | |
ref_platform.all().map(|all| { | |
all.try_for_each(|reference| -> Result<()> { | |
let reference = reference?; | |
if let Some((_, name)) = reference.name().category_and_short_name() { | |
refs.push(name.to_string()); | |
} | |
Ok(()) | |
})?; | |
Ok(refs) | |
})? |
/// Return completions for all Git branches starting with `current` in the current directory | ||
/// Used in `--to-branch` option | ||
pub fn git_branch_completer(current: &std::ffi::OsStr) -> Vec<CompletionCandidate> { | ||
let current = current.to_string_lossy(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🐛 Possible Bug
Converting OsStr
to string using to_string_lossy()
could lead to data loss or unexpected behavior with invalid Unicode sequences. Consider handling non-Unicode paths explicitly.
let current = current.to_string_lossy(); | |
let current = match current.to_str() { | |
Some(s) => s.to_string(), | |
None => return Vec::new(), // or handle invalid Unicode explicitly | |
}; |
@@ -194,17 +205,16 @@ pub fn cmd_pipeline<R: BufRead>( | |||
// This should already be filled from the conf if not given | |||
let pipeline_name = command.pipeline_name.unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🐛 Possible Bug
Using unwrap()
on pipeline_name
can cause a panic if the value is None. Even though there's a comment suggesting it should be filled from config, it's better to handle the None case explicitly with proper error handling.
let pipeline_name = command.pipeline_name.unwrap(); | |
let pipeline_name = command.pipeline_name.ok_or_else(|| anyhow::anyhow!("Pipeline name is required but not provided"))? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Key Issues
The PR review highlights critical issues including potential data loss from improper OsStr to str conversion, unhandled feature flags leading to compile-time or runtime errors, and insufficient error handling in file system operations that could cause program crashes or partial initialization.
/// Return all step names starting with `prefix` | ||
pub fn step_name_completer(prefix: &OsStr) -> Vec<CompletionCandidate> { | ||
// This must be safe as we don't allow Non-UTF-8 strings for storage identifiers | ||
let prefix = prefix.to_str().unwrap_or(""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🐛 Possible Bug
Using unwrap_or("")
on OsStr to str conversion could lead to data loss or incorrect behavior if the prefix contains non-UTF8 characters. Since this is used for name matching, it could cause valid matches to be missed.
let prefix = prefix.to_str().unwrap_or(""); | |
let prefix = prefix.to_str().unwrap_or_else(|| { | |
log::warn!("Non-UTF8 prefix received: {:?}", prefix); | |
"" | |
}); |
match self { | ||
XvcStorage::Local(lr) => lr.send(output, xvc_root, paths, force), | ||
XvcStorage::Generic(gr) => gr.send(output, xvc_root, paths, force), | ||
XvcStorage::Rsync(r) => r.send(output, xvc_root, paths, force), | ||
#[cfg(feature = "s3")] | ||
XvcStorage::S3(s3r) => s3r.send(output, xvc_root, paths, force), | ||
#[cfg(feature = "minio")] | ||
XvcStorage::Minio(mr) => mr.send(output, xvc_root, paths, force), | ||
#[cfg(feature = "r2")] | ||
XvcStorage::R2(r) => r.send(output, xvc_root, paths, force), | ||
#[cfg(feature = "gcs")] | ||
XvcStorage::Gcs(r) => r.send(output, xvc_root, paths, force), | ||
#[cfg(feature = "wasabi")] | ||
XvcStorage::Wasabi(r) => r.send(output, xvc_root, paths, force), | ||
#[cfg(feature = "digital-ocean")] | ||
XvcStorage::DigitalOcean(r) => r.send(output, xvc_root, paths, force), | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🐛 Possible Bug
The code doesn't handle the case where a storage type is used but its feature flag is not enabled. This could lead to compile-time errors or runtime issues if the code tries to use a storage type that isn't available.
match self { | |
XvcStorage::Local(lr) => lr.send(output, xvc_root, paths, force), | |
XvcStorage::Generic(gr) => gr.send(output, xvc_root, paths, force), | |
XvcStorage::Rsync(r) => r.send(output, xvc_root, paths, force), | |
#[cfg(feature = "s3")] | |
XvcStorage::S3(s3r) => s3r.send(output, xvc_root, paths, force), | |
#[cfg(feature = "minio")] | |
XvcStorage::Minio(mr) => mr.send(output, xvc_root, paths, force), | |
#[cfg(feature = "r2")] | |
XvcStorage::R2(r) => r.send(output, xvc_root, paths, force), | |
#[cfg(feature = "gcs")] | |
XvcStorage::Gcs(r) => r.send(output, xvc_root, paths, force), | |
#[cfg(feature = "wasabi")] | |
XvcStorage::Wasabi(r) => r.send(output, xvc_root, paths, force), | |
#[cfg(feature = "digital-ocean")] | |
XvcStorage::DigitalOcean(r) => r.send(output, xvc_root, paths, force), | |
} | |
match self { | |
XvcStorage::Local(lr) => lr.send(output, xvc_root, paths, force), | |
XvcStorage::Generic(gr) => gr.send(output, xvc_root, paths, force), | |
XvcStorage::Rsync(r) => r.send(output, xvc_root, paths, force), | |
#[cfg(feature = "s3")] | |
XvcStorage::S3(s3r) => s3r.send(output, xvc_root, paths, force), | |
#[cfg(feature = "minio")] | |
XvcStorage::Minio(mr) => mr.send(output, xvc_root, paths, force), | |
#[cfg(feature = "r2")] | |
XvcStorage::R2(r) => r.send(output, xvc_root, paths, force), | |
#[cfg(feature = "gcs")] | |
XvcStorage::Gcs(r) => r.send(output, xvc_root, paths, force), | |
#[cfg(feature = "wasabi")] | |
XvcStorage::Wasabi(r) => r.send(output, xvc_root, paths, force), | |
#[cfg(feature = "digital-ocean")] | |
XvcStorage::DigitalOcean(r) => r.send(output, xvc_root, paths, force), | |
_ => Err(anyhow::anyhow!("Storage type not available. Enable the corresponding feature flag.")) |
let abs_path = PathBuf::from(path) | ||
.canonicalize() | ||
.expect("Cannot canonicalize the path. Possible symlink loop."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🐛 Possible Bug
Using expect()
on canonicalize()
will cause the program to panic if there's a symlink loop or permission issues. This should be handled gracefully with proper error propagation.
let abs_path = PathBuf::from(path) | |
.canonicalize() | |
.expect("Cannot canonicalize the path. Possible symlink loop."); | |
let abs_path = PathBuf::from(path) | |
.canonicalize() | |
.map_err(|e| Error::PathCanonicalizeError { path: path.into(), source: e })? |
core/src/util/completer.rs
Outdated
// FIXME: This doesn't consider current dir to filter the elements | ||
let filtered = xvc_path_store.filter(|_, xp| xp.starts_with_str(&prefix)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🐛 Possible Bug
The code collects all paths that start with the prefix without considering the current directory, which could lead to performance issues with large repositories and return irrelevant results. The FIXME comment acknowledges this, but the current implementation could cause confusion for users.
// FIXME: This doesn't consider current dir to filter the elements | |
let filtered = xvc_path_store.filter(|_, xp| xp.starts_with_str(&prefix)); | |
let current_dir_str = current_dir.to_str().ok_or(Error::NonUtf8Path)?; | |
let filtered = xvc_path_store.filter(|_, xp| { | |
xp.starts_with_str(current_dir_str) && xp.starts_with_str(prefix) | |
}); |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #265 +/- ##
==========================================
- Coverage 71.80% 71.21% -0.59%
==========================================
Files 123 125 +2
Lines 14172 14313 +141
==========================================
+ Hits 10176 10193 +17
- Misses 3996 4120 +124 ☔ View full report in Codecov by Sentry. |
✨
Description by Callstackai
This PR introduces CLI completions for various commands, enhances error handling, and updates dependencies to version 0.6.14-alpha.8.
Diagrams of code changes
Files Changed
This PR includes files in programming languages that we currently do not support. We have not reviewed files with the extensions
.md
,.toml
,.zsh
. See list of supported languages.