You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The code assumes that all values in self.values are valid indices into JobStatus::VARIANTS, but this may not be true when 'All' is selected. The index calculation should account for the offset caused by inserting "All" at index 0.
let selected_statuses = self
.values
.iter()
- .map(|v| <JobStatus as VariantArray>::VARIANTS[*v - 1].clone())+ .filter(|&&v| v != 0) // Skip 'All' selection+ .map(|&v| <JobStatus as VariantArray>::VARIANTS[v - 1].clone())
.collect();
Suggestion importance[1-10]: 8
__
Why: The suggestion identifies a potential bug in the index calculation when mapping selected values back to JobStatus variants. The code assumes all indices are valid, but when 'All' is selected, the indexing needs adjustment. This could lead to incorrect job status filtering, making it a medium-high impact issue.
Medium
Prevent potential panic during job status conversion
The conversion from string to JobStatus uses unwrap() which can cause a panic if the input string is malformed. A safer approach would be to return an error or default value instead.
Why: While the suggestion correctly identifies a potential panic risk with unwrap(), the fix suggested (unwrap_or("")) doesn't fully resolve the issue since the code still relies on .split_whitespace().next() which could return None. However, this is a reasonable improvement for robustness, though not critical.
Medium
General
Simplify job listing with optional filtering
The filtering logic does not properly handle the case where status is None. It should still return all jobs when no filter is applied, which is currently handled correctly, but the function signature suggests it could be simplified.
+pub async fn list_jobs(+ &self,+ status: Option<Vec<JobStatus>>,+ system_name: &str,+ all_users: Option<bool>,+) -> Result<Vec<Job>> {+ let result = get_compute_system_jobs(&self.client, system_name, all_users)+ .await+ .wrap_err("couldn't fetch cscs jobs")?;+ let mut result: Vec<Job> = result+ .jobs+ .map(|jobs| jobs.into_iter().map(|j| j.into()).collect())+ .unwrap_or(vec![]);+ if let Some(filter) = status {+ result.retain(|j| filter.contains(&j.status));+ }+ Ok(result)+}-
Suggestion importance[1-10]: 3
__
Why: The suggestion proposes simplifying the function, but the existing implementation already correctly handles the None case. The function signature and logic are already appropriate, so this suggestion offers minimal improvement and doesn't address any real issue.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #20