1
Fork 0

don't panic on failure

This commit is contained in:
Andy Killorin 2023-12-24 15:56:10 -06:00
parent 8419f1654e
commit 923fa7aa9b
Signed by: ank
GPG key ID: B6241CA3B552BCA4
2 changed files with 8 additions and 4 deletions

View file

@ -1,6 +1,6 @@
use std::ops::{Mul, Add};
use log::{trace, warn, info};
use log::{trace, warn, info, error};
use nalgebra::Vector2;
use serde::{Serialize, Deserialize};
use time::OffsetDateTime;
@ -142,7 +142,9 @@ impl Task for TreeFarm {
fn run(&mut self,turtle:TurtleCommander) -> AbortHandle {
let frozen = self.clone();
tokio::spawn(async move {
frozen.sweep(turtle).await.unwrap();
if let None = frozen.sweep(turtle).await {
error!("felling at {} failed", frozen.position);
}
}).abort_handle()
}

View file

@ -1,6 +1,6 @@
use std::sync::{Arc, atomic::{AtomicUsize, Ordering, AtomicI32}};
use log::{info, warn};
use log::{info, warn, error};
use serde::{Serialize, Deserialize};
use tokio::task::{JoinHandle, AbortHandle};
use typetag::serde;
@ -263,7 +263,9 @@ impl Task for Quarry {
// TODO: handle failure
// another turtle should get the next chunk while this is in flight, but program
// termination or a None return should reschedule the chunk
mine_chunk_and_sweep(turtle, abs_pos, max_chunk).await.unwrap();
if let None = mine_chunk_and_sweep(turtle, abs_pos, max_chunk).await {
error!("mining at {abs_pos} failed");
}
owned.fetch_sub(1, Ordering::AcqRel);
}).abort_handle()
}