1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-07 19:09:20 +00:00

refactor: improve sudo error handling to distinguish authentication failures and adjust scene view rotation speed.

This commit is contained in:
Tw93
2025-12-15 15:09:40 +08:00
parent 4547f5819e
commit 4c18957aae
4 changed files with 55 additions and 11 deletions

View File

@@ -144,12 +144,23 @@ class ScannerService: ObservableObject {
do {
_ = try await ShellRunner.shared.runSudo(fullCommand, password: sessionPw)
} catch {
print("Sudo command error: \(error)")
print("Session password failed: \(error)")
await MainActor.run { AuthContext.shared.clear() }
// Trigger re-auth on failure
if case ShellError.authenticationFailed = error {
await MainActor.run {
AuthContext.shared.clear()
AuthContext.shared.needsPassword = true
self.currentLog = "Password Incorrect/Expired"
self.isCleaning = false
}
return 0
}
// Ignore other errors (e.g. command execution failed)
// but continue the flow or handle gracefully without clearing password
print("Non-auth error in cleanup: \(error)")
await MainActor.run {
AuthContext.shared.needsPassword = true
self.currentLog = "Password Incorrect/Expired"
self.currentLog = "Error: \(error.localizedDescription)"
self.isCleaning = false
}
return 0