Explain runtime invariants and avoid redundant unwraps

This commit is contained in:
Samuel Onoja committed 2026-10-22 01:28:03 +01:00
1 parent 34f2f07301
commit 1b51ba83b4
116 files changed
+1643 -515

No files matched your search

+14 -3
View File
@@ -136,7 +136,10 @@ impl Agent {
let cancelled = Arc::new(AtomicBool::new(false));
{
let mut active = self.active.lock().unwrap();
let mut active = self
.active
.lock()
.expect("authentication session ownership must remain consistent across callbacks");
if active.contains_key(&cookie) {
return Err(zbus::fdo::Error::Failed("Duplicate request".into()));
}
@@ -166,7 +169,10 @@ impl Agent {
})
.await;
self.active.lock().unwrap().remove(&cookie);
self.active
.lock()
.expect("authentication session ownership must remain consistent across callbacks")
.remove(&cookie);
match result.map_err(|error| zbus::fdo::Error::Failed(error.to_string()))? {
Ok(true) => Ok(()),
Ok(false) => Err(zbus::fdo::Error::Failed("Authentication cancelled".into())),
@@ -175,7 +181,12 @@ impl Agent {
}
fn cancel_authentication(&self, cookie: String) {
if let Some(cancelled) = self.active.lock().unwrap().get(&cookie) {
if let Some(cancelled) = self
.active
.lock()
.expect("authentication session ownership must remain consistent across callbacks")
.get(&cookie)
{
cancelled.store(true, Ordering::Release);
}
}
+14 -3
View File
@@ -153,11 +153,17 @@ fn read_events(
for line in lines {
let Ok(line) = line else { break };
if let Ok(event) = serde_json::from_str(&line) {
queue.lock().unwrap().push_back(event);
queue
.lock()
.expect("authentication prompt queue must remain consistent across workers")
.push_back(event);
}
}
// The agent owns this pipe. EOF (including agent death) closes the prompt.
queue.lock().unwrap().push_back(PromptEvent::Cancel);
queue
.lock()
.expect("authentication prompt queue must remain consistent across workers")
.push_back(PromptEvent::Cancel);
}
pub fn run() -> Result<(), Box<dyn std::error::Error>> {
@@ -348,7 +354,12 @@ impl cosmic::Application for Prompt {
self.material = result.ok();
}
Message::Tick => {
let events: Vec<_> = self.incoming.lock().unwrap().drain(..).collect();
let events: Vec<_> = self
.incoming
.lock()
.expect("authentication prompt queue must remain consistent across workers")
.drain(..)
.collect();
let mut refocus = false;
for event in events {
match event {
+3 -1
View File
@@ -469,7 +469,9 @@ fn run_session(
} else if stopped {
Ok(SessionOutcome::Cancelled)
} else {
Ok(SessionOutcome::Completed(outcome.unwrap()))
Ok(SessionOutcome::Completed(outcome.expect(
"the session loop finished only after receiving a completion outcome",
)))
}
}