Skip to content

fix async self-update, check user permissions on login#66

Merged
Panaetius merged 2 commits intomainfrom
fix-update-and-permissions
Mar 2, 2026
Merged

fix async self-update, check user permissions on login#66
Panaetius merged 2 commits intomainfrom
fix-update-and-permissions

Conversation

@Panaetius
Copy link
Member

closes #65
also sets default job timeout to 10 hours as some systems don't allow high values like 24 hours

@Panaetius Panaetius requested a review from a team as a code owner March 2, 2026 13:11
@github-actions
Copy link

github-actions bot commented Mar 2, 2026

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Handle API client creation errors gracefully

The unwrap() call on CscsApi::new() can panic if the platform is invalid; replace it
with proper error handling to make the login process more robust.

coman/src/cscs/handlers.rs [88-105]

 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.

coman/src/cli/app.rs [607-608]

-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.

coman/src/config.rs [335-345]

 // 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.

Low

@Panaetius Panaetius force-pushed the fix-update-and-permissions branch from 29c36c2 to 501b613 Compare March 2, 2026 13:32
@Panaetius Panaetius merged commit 463eb65 into main Mar 2, 2026
2 checks passed
@Panaetius Panaetius deleted the fix-update-and-permissions branch March 2, 2026 13:56
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.

check platform access on login

1 participant