Skip to content

Commit d340155

Browse files
committed
chore: if there is no stored credential, return null instead of throwing
1 parent 4bd0c20 commit d340155

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src-tauri/src/main.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,9 @@ fn delete_credential(scope_name: String) -> Result<(), String> {
422422
}
423423

424424
// Gets the stored credential, encrypts it with the window's AES key, and returns the encrypted value
425+
// Returns None if no credential is found
425426
#[tauri::command]
426-
fn get_credential(window: tauri::Window, scope_name: String, trust_state: State<'_, WindowAesTrust>) -> Result<String, String> {
427+
fn get_credential(window: tauri::Window, scope_name: String, trust_state: State<'_, WindowAesTrust>) -> Result<Option<String>, String> {
427428
let window_label = window.label().to_string();
428429

429430
// Check if AES trust is established for this window
@@ -443,7 +444,7 @@ fn get_credential(window: tauri::Window, scope_name: String, trust_state: State<
443444

444445
let stored_credential = match entry.get_password() {
445446
Ok(data) => data,
446-
Err(keyring::Error::NoEntry) => return Err("No credential found for the specified scope.".to_string()),
447+
Err(keyring::Error::NoEntry) => return Ok(None), // Return None if no credential found
447448
Err(e) => return Err(format!("Failed to retrieve credential: {}", e.to_string())),
448449
};
449450

@@ -471,8 +472,8 @@ fn get_credential(window: tauri::Window, scope_name: String, trust_state: State<
471472
let encrypted_data = cipher.encrypt(nonce, stored_credential.as_bytes())
472473
.map_err(|_| "Failed to encrypt credential".to_string())?;
473474

474-
// Return the encrypted data as a hex string
475-
Ok(hex::encode(encrypted_data))
475+
// Return the encrypted data as a hex string wrapped in Some
476+
Ok(Some(hex::encode(encrypted_data)))
476477
}
477478

478479
fn main() {

0 commit comments

Comments
 (0)