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
let token = client_credentials_login(client_id_secret, client_secret_secret).await?;
// figure out what platform the user has access to and set it in config
let mut config = Config::new()?;
let source = config.value_source("cscs.current_platform")?;
if source.1 || source.2 {
// don't override setting if it's already provided
return Ok(());
}
for platform in ComputePlatform::iter() {
- let api_client = CscsApi::new(token.0.0.clone(), Some(platform.clone())).unwrap();- if (api_client.list_systems().await).is_ok() {- config.set("cscs.current_platform", platform.to_string(), true)?;- break;+ match CscsApi::new(token.0.0.clone(), Some(platform.clone())) {+ Ok(api_client) => {+ if api_client.list_systems().await.is_ok() {+ config.set("cscs.current_platform", platform.to_string(), true)?;+ break;+ }+ }+ Err(_) => continue, // Skip invalid platforms instead of panicking
}
}
Ok(())
Suggestion importance[1-10]: 8
__
Why: The suggestion correctly identifies a potential panic from unwrap() on CscsApi::new() and provides a better approach using match to handle the error gracefully. This improves robustness by preventing crashes due to invalid platform configurations.
Medium
Improve error handling in async update call
The update function is called within a blocking task, but the error handling could be improved to ensure proper propagation of errors from the update operation.
-update()?;+let result = tokio::task::spawn_blocking(update).await??;
std::fs::write(&stamp_path, Local::now().to_rfc3339())?;
+result
Suggestion importance[1-10]: 3
__
Why: The suggestion proposes changing the error handling for the update function call, but the actual change doesn't significantly improve error propagation since tokio::task::spawn_blocking(update).await?? already handles errors properly. The suggested reassignment of result is unnecessary and doesn't add value.
Low
General
Improve configuration access error handling
The use of unwrap_or_default() may hide potential configuration issues; consider returning a more explicit error when accessing nested configuration layers fails.
// Returns tuple of bool saying whether a values is set in (default, global, project local) config
pub fn value_source(&self, key_path: &str) -> Result<(bool, bool, bool)> {
Ok((
self.default_layer.get(key_path).is_some(),
- self.global_layer.get(key_path).unwrap_or_default().is_some(),+ self.global_layer.get(key_path).is_some(),
self.project_layer
.as_ref()
- .map(|l| l.get(key_path).unwrap_or_default().is_some())+ .map(|l| l.get(key_path).is_some())
.unwrap_or(false),
))
}
Suggestion importance[1-10]: 5
__
Why: The suggestion addresses a potential issue with unwrap_or_default() in configuration access, which could mask errors. However, the improvement is moderate because the current implementation likely works correctly in practice, and the change only affects error reporting rather than core functionality.
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 #65
also sets default job timeout to 10 hours as some systems don't allow high values like 24 hours