Skip to content

Commit 5d97b0a

Browse files
authored
Merge pull request #28 from ilikepi63/chore/implement-unwrap-clippy-lint
chore: Add Unwrap Clippy Lint
2 parents 43a8b94 + de80644 commit 5d97b0a

File tree

5 files changed

+59
-8
lines changed

5 files changed

+59
-8
lines changed

.github/workflows/check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
steps:
1414
- uses: actions/checkout@v4
1515
- name: Run Clippy
16-
run: cargo clippy --all-features --all-targets
16+
run: cargo clippy --all-features
1717
coverage:
1818
runs-on: ubuntu-latest
1919
env:

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "riskless"
3-
version = "0.4.2"
3+
version = "0.4.3"
44
edition = "2024"
55
description = "A pure Rust implementation of Diskless Topics"
66
license = "MIT / Apache-2.0"

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

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// #![deny(missing_docs)]
22
#![deny(clippy::print_stdout)]
33
#![deny(clippy::print_stderr)]
4+
#![deny(clippy::unwrap_used)]
5+
46

57
pub mod batch_coordinator;
68
mod utils;

0 commit comments

Comments
 (0)