Skip to content

Commit 308df4b

Browse files
committed
chore: Removed Unwraps from SimpleBatchCoordinator
1 parent 3462f3f commit 308df4b

File tree

1 file changed

+54
-5
lines changed
  • src/batch_coordinator/simple

1 file changed

+54
-5
lines changed

src/batch_coordinator/simple/mod.rs

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,64 @@ impl BatchCoordinator for SimpleBatchCoordinator {
180180
Ok(mut file) => {
181181
tracing::info!("Reading from position: {:#?}", request.offset);
182182

183-
let size_in_u64: u64 = Index::packed_size().try_into().unwrap();
183+
let size_in_u64: u64 = match Index::packed_size().try_into() {
184+
Ok(s) => s,
185+
Err(err) => {
186+
let message = format!(
187+
"Failed to convert Index size into u64 with error: {:#?}",
188+
err
189+
);
190+
191+
results.push(FindBatchResponse {
192+
errors: vec![err.to_string()],
193+
batches: vec![],
194+
log_start_offset: request.offset,
195+
high_watermark: 0,
196+
});
197+
198+
tracing::error!(message);
199+
continue;
200+
}
201+
};
202+
203+
// Seek to the desired offset in the file.
204+
match file.seek(std::io::SeekFrom::Start(request.offset * size_in_u64)) {
205+
Ok(_) => {}
206+
Err(err) => {
207+
let message =
208+
format!("Failed to Seek in file with resultant error: {:#?}", err);
209+
210+
results.push(FindBatchResponse {
211+
errors: vec![err.to_string()],
212+
batches: vec![],
213+
log_start_offset: request.offset,
214+
high_watermark: 0,
215+
});
184216

185-
let _result = file
186-
.seek(std::io::SeekFrom::Start(request.offset * size_in_u64))
187-
.unwrap();
217+
tracing::error!(message);
218+
continue;
219+
}
220+
};
188221

189222
let mut buf: [u8; 28] = [0; Index::packed_size()];
190223

191-
file.read_exact(&mut buf).unwrap();
224+
match file.read_exact(&mut buf) {
225+
Ok(_) => {}
226+
Err(err) => {
227+
let message =
228+
format!("Failed to read bytes from file with error: {:#?}", err);
229+
230+
results.push(FindBatchResponse {
231+
errors: vec![err.to_string()],
232+
batches: vec![],
233+
log_start_offset: request.offset,
234+
high_watermark: 0,
235+
});
236+
237+
tracing::error!(message);
238+
continue;
239+
}
240+
};
192241

193242
let index = Index::try_from(buf.as_ref());
194243

0 commit comments

Comments
 (0)