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

+3 -1
View File
@@ -423,7 +423,9 @@ pub fn run(
});
let status = child.wait()?;
CHILD.store(0, std::sync::atomic::Ordering::Relaxed);
*drain_deadline.lock().unwrap() =
*drain_deadline
.lock()
.expect("command output drain deadline must remain consistent across reader and waiter") =
Some(std::time::Instant::now() + std::time::Duration::from_millis(250));
if let Some(reader) = reader {
// Descendants may inherit the pipe after the direct child exits. Drain
+3 -1
View File
@@ -19,7 +19,9 @@ impl Read for Output {
if self
.deadline
.lock()
.unwrap()
.expect(
"command output drain deadline must remain consistent across reader and waiter",
)
.is_some_and(|deadline| Instant::now() >= deadline)
{
// EOF lets BufReader return its final unterminated line too.
+11 -5
View File
@@ -16,7 +16,9 @@ pub(super) struct Updates(Arc<(Mutex<Pending>, Condvar)>);
impl Updates {
pub fn progress(&self, units: u64) {
let (lock, wake) = &*self.0;
let mut pending = lock.lock().unwrap();
let mut pending = lock.lock().expect(
"the bounded progress buffer was checked before removing bytes or parsing text",
);
if !pending.closed {
pending.units = Some(units);
wake.notify_one();
@@ -36,9 +38,11 @@ impl Publisher {
std::thread::spawn(move || {
loop {
let (lock, wake) = &*worker.0;
let mut pending = lock.lock().unwrap();
let mut pending = lock.lock().expect(
"the bounded progress buffer was checked before removing bytes or parsing text",
);
while pending.units.is_none() && pending.end.is_none() {
pending = wake.wait(pending).unwrap();
pending = wake.wait(pending).expect("the bounded progress buffer was checked before removing bytes or parsing text");
}
let end = pending.end.take();
let units = pending.units.take();
@@ -54,7 +58,7 @@ impl Publisher {
Publish::Update {
local: local.clone(),
handle: Some(handle.clone()),
value: Some(Value::Text(format!("{} units compiled", units.unwrap()))),
value: Some(Value::Text(format!("{} units compiled", units.expect("the bounded progress buffer was checked before removing bytes or parsing text")))),
lease_ms: None,
}
};
@@ -76,7 +80,9 @@ impl Publisher {
pub fn finish(self, result: State) {
let (lock, wake) = &*self.updates.0;
{
let mut pending = lock.lock().unwrap();
let mut pending = lock.lock().expect(
"the bounded progress buffer was checked before removing bytes or parsing text",
);
pending.closed = true;
pending.units = None;
pending.end = Some(result);
+18 -4
View File
@@ -15,7 +15,11 @@ fn prepare(source: &str) -> Result<String, Box<dyn Error>> {
serde_json::to_value(vec![panel::Panel::default()])?,
)?;
}
let panels: Vec<panel::Panel> = serde_json::from_value(doc.get("panels").unwrap().clone())?;
let panels: Vec<panel::Panel> = serde_json::from_value(
doc.get("panels")
.expect("setup populated the panel document before validation")
.clone(),
)?;
panel::validate(&panels)?;
for (index, bar) in panels.iter().enumerate() {
let groups = [&bar.start, &bar.center, &bar.end]
@@ -47,7 +51,11 @@ fn prepare(source: &str) -> Result<String, Box<dyn Error>> {
if let Some(zone) = zone {
doc.add(
&format!("panels.{index}.{zone}.groups.0.items"),
item.as_object().unwrap().clone().into_iter().collect(),
item.as_object()
.expect("serialized panel items are JSON objects")
.clone()
.into_iter()
.collect(),
)?;
} else {
doc.add(
@@ -59,7 +67,11 @@ fn prepare(source: &str) -> Result<String, Box<dyn Error>> {
)?;
}
}
let panels = serde_json::from_value::<Vec<panel::Panel>>(doc.get("panels").unwrap().clone())?;
let panels = serde_json::from_value::<Vec<panel::Panel>>(
doc.get("panels")
.expect("setup populated the panel document before validation")
.clone(),
)?;
panel::validate(&panels)?;
Ok(doc.to_string())
}
@@ -72,7 +84,9 @@ pub fn configure(path: &Path) -> Result<(), Box<dyn Error>> {
}
let backup = path.with_file_name(format!(
"{}.before-activities-{}",
path.file_name().unwrap().to_string_lossy(),
path.file_name()
.expect("the configured shell hook path identifies a file")
.to_string_lossy(),
ferese_ipc::activities::now_ms()
));
file.replace(&desired, Some(&backup), |_| Ok(()))?;
+1 -1
View File
@@ -119,7 +119,7 @@ fn theme_command(
}
ThemeAction::Mode { mode } => connection.call(
"theme-set-mode",
json!({"mode": mode.to_possible_value().unwrap().get_name()}),
json!({"mode": mode.to_possible_value().expect("every ThemeMode variant has a Clap value name").get_name()}),
)?,
ThemeAction::Preview { path } => connection.call(
"theme-preview",