Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Report error from submit_file() in shim #132

Merged
merged 3 commits into from
Mar 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions crates/shim/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl GRPCClient {

fn submit_file(&mut self, task_id: TaskId, file_path: String) -> Result<[u8; 32]> {
let hasher = Arc::new(Mutex::new(blake3::Hasher::new()));
self.rt.block_on(async {
let res = self.rt.block_on(async {
let stream_hasher = Arc::clone(&hasher);
let outbound = async_stream::stream! {

Expand All @@ -185,26 +185,24 @@ impl GRPCClient {
match file.read(&mut buf).await {
Ok(0) => return,
Ok(n) => {

stream_hasher.lock().await.update(&buf[..n]);
yield FileData{ result: Some(grpc::file_data::Result::Chunk(FileChunk{ data: buf[..n].to_vec() }))};
},
Err(err) => {
println!("failed to read file: {}", err);
yield FileData{ result: Some(grpc::file_data::Result::Error(1))};
break;
}
}
}
};

if let Err(err) = self.client.lock().await.submit_file(Request::new(outbound)).await {
println!("failed to submit file: {}", err);
}
self.client.lock().await.submit_file(Request::new(outbound)).await
});
let hasher = Arc::into_inner(hasher).unwrap().into_inner();
let hash = hasher.finalize().into();
let checksum = hasher.finalize().into();

Ok(hash)
res.map(|_| checksum).map_err(|err| err.into())
}

fn submit_result(&mut self, result: &TaskResult) -> Result<bool> {
Expand Down Expand Up @@ -348,7 +346,13 @@ pub fn run(callback: impl Fn(&Task) -> Result<TaskResult>) -> Result<()> {

let result = callback(&task)?;

let should_continue = client.submit_result(&result)?;
let should_continue = match client.submit_result(&result) {
Ok(res) => res,
Err(err) => {
println!("An error occurs during submit_result {err}");
return Err(err);
}
};
if !should_continue {
break;
}
Expand Down
Loading