Skip to content

Commit ad4a840

Browse files
committed
Use or_panic instead of expect
1 parent 2608afa commit ad4a840

File tree

35 files changed

+126
-51
lines changed

35 files changed

+126
-51
lines changed

.github/workflows/rust.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
components: clippy, rustfmt
2626

2727
- name: Run Clippy
28-
run: cargo clippy -- -D warnings --allow unused_variables
28+
run: cargo clippy -- -D warnings -D clippy::expect_used -D clippy::unwrap_used --allow unused_variables
2929

3030
- name: Cargo fmt check
3131
run: cargo fmt --check --all

Cargo.lock

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ size-parser = { path = "size-parser" }
8686

8787
# Core dependencies
8888
anyhow = { version = "1.0.97", default-features = false }
89+
or-panic = { version = "1.0", default-features = false }
8990
chrono = "0.4.40"
9091
clap = { version = "4.5.32", features = ["derive", "string"] }
9192
dashmap = "6.1.0"

certbot/cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ tokio = { workspace = true, features = ["full"] }
2424
toml_edit.workspace = true
2525
tracing-subscriber.workspace = true
2626
rustls.workspace = true
27+
or-panic.workspace = true

certbot/cli/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use certbot::{CertBotConfig, WorkDir};
1010
use clap::Parser;
1111
use documented::DocumentedFields;
1212
use fs_err as fs;
13+
use or_panic::ResultOrPanic;
1314
use serde::{Deserialize, Serialize};
1415
use toml_edit::ser::to_document;
1516

@@ -166,7 +167,7 @@ async fn main() -> Result<()> {
166167
}
167168
rustls::crypto::ring::default_provider()
168169
.install_default()
169-
.expect("Failed to install default crypto provider");
170+
.or_panic("Failed to install default crypto provider");
170171

171172
let args = Args::parse();
172173
match args.command {

dstack-mr/src/acpi.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
88
use anyhow::{bail, Context, Result};
99
use log::debug;
10+
use scale::Decode;
1011

1112
use crate::Machine;
1213

@@ -392,6 +393,13 @@ fn qemu_loader_append(data: &mut Vec<u8>, cmd: LoaderCmd) {
392393
}
393394
}
394395

396+
/// ACPI table header (first 8 bytes of every ACPI table)
397+
#[derive(Debug, Decode)]
398+
struct AcpiTableHeader {
399+
signature: [u8; 4],
400+
length: u32,
401+
}
402+
395403
/// Searches for an ACPI table with the given signature and returns its offset,
396404
/// checksum offset, and length.
397405
fn find_acpi_table(tables: &[u8], signature: &str) -> Result<(u32, u32, u32)> {
@@ -407,24 +415,21 @@ fn find_acpi_table(tables: &[u8], signature: &str) -> Result<(u32, u32, u32)> {
407415
bail!("Table not found: {signature}");
408416
}
409417

410-
let tbl_sig = &tables[offset..offset + 4];
411-
let tbl_len_bytes: [u8; 4] = tables[offset + 4..offset + 8]
412-
.try_into()
413-
.expect("header len checked");
414-
let tbl_len = u32::from_le_bytes(tbl_len_bytes) as usize;
418+
let header = AcpiTableHeader::decode(&mut &tables[offset..])
419+
.context("failed to decode ACPI table header")?;
415420

416-
if tbl_sig == sig_bytes {
421+
if header.signature == sig_bytes {
417422
// Found the table
418-
return Ok((offset as u32, (offset + 9) as u32, tbl_len as u32));
423+
return Ok((offset as u32, (offset + 9) as u32, header.length));
419424
}
420425

421-
if tbl_len == 0 {
426+
if header.length == 0 {
422427
// Invalid table length, stop searching
423-
bail!("Found table with zero length at offset {offset}");
428+
bail!("found table with zero length at offset {offset}");
424429
}
425430
// Move to the next table
426-
offset += tbl_len;
431+
offset += header.length as usize;
427432
}
428433

429-
bail!("Table not found: {signature}");
434+
bail!("table not found: {signature}");
430435
}

dstack-mr/src/tdvf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ impl<'a> Tdvf<'a> {
341341
td_hob.extend_from_slice(&length.to_le_bytes());
342342
};
343343

344-
let (_, last_start, last_end) = memory_acceptor.ranges.pop().expect("No ranges");
344+
let (_, last_start, last_end) = memory_acceptor.ranges.pop().context("No ranges")?;
345345

346346
for (accepted, start, end) in memory_acceptor.ranges {
347347
if end < start {

gateway/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ reqwest = { workspace = true, features = ["json"] }
5050
hyper = { workspace = true, features = ["server", "http1"] }
5151
hyper-util = { version = "0.1", features = ["tokio"] }
5252
jemallocator.workspace = true
53+
or-panic.workspace = true
5354

5455
[target.'cfg(unix)'.dependencies]
5556
nix = { workspace = true, features = ["resource"] }

gateway/rpc/build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
//
33
// SPDX-License-Identifier: Apache-2.0
44

5+
#![allow(clippy::expect_used)]
6+
57
fn main() {
68
prpc_build::configure()
79
.out_dir(std::env::var_os("OUT_DIR").expect("OUT_DIR not set"))

gateway/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ async fn main() -> Result<()> {
167167
info!("Starting background tasks");
168168
state.start_bg_tasks().await?;
169169
state.lock().reconfigure()?;
170-
proxy::start(proxy_config, state.clone());
170+
171+
proxy::start(proxy_config, state.clone()).context("failed to start the proxy")?;
171172

172173
let admin_figment =
173174
Figment::new()

0 commit comments

Comments
 (0)