Skip to content
Draft
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion lading/src/blackhole/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ fn default_headers() -> HeaderMap {
header::CONTENT_TYPE,
"application/json"
.parse()
.expect("Not possible to parse into HeaderMap"),
.unwrap_or_else(|_| unreachable!("\"application/json\" is a valid HeaderValue")),
);
map
}
Expand Down
4 changes: 2 additions & 2 deletions lading/src/blackhole/tcp_rr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ use crate::neper::metrics::{self, ThreadMetrics};
use crate::neper::thread;

fn default_nonzero_u16() -> NonZeroU16 {
NonZeroU16::new(1).expect("1 is nonzero")
NonZeroU16::new(1).unwrap_or_else(|| unreachable!("1 is nonzero by construction"))
}

fn default_nonzero_usize() -> NonZeroUsize {
NonZeroUsize::new(1).expect("1 is nonzero")
NonZeroUsize::new(1).unwrap_or_else(|| unreachable!("1 is nonzero by construction"))
}

fn default_control_port() -> u16 {
Expand Down
8 changes: 6 additions & 2 deletions lading/src/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ pub(crate) fn decode(
.body(crate::full(format!(
"Unsupported encoding type: {encoding}"
)))
.expect("failed to build response"),
.unwrap_or_else(|_| {
unreachable!(
"Response::builder().body() on an OK builder cannot fail"
)
}),
));
}
}
Expand All @@ -85,5 +89,5 @@ fn encoding_error_to_response(
.body(crate::full(format!(
"failed to decode input as {encoding}: {error}"
)))
.expect("failed to build response")
.unwrap_or_else(|_| unreachable!("Response::builder().body() on an OK builder cannot fail"))
}
6 changes: 4 additions & 2 deletions lading/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ impl Default for Telemetry {
Self::Prometheus {
addr: "0.0.0.0:9000"
.parse()
.expect("Not possible to parse to SocketAddr"),
.unwrap_or_else(|_| unreachable!("\"0.0.0.0:9000\" is a valid SocketAddr literal")),
global_labels: FxHashMap::default(),
}
}
Expand Down Expand Up @@ -484,7 +484,9 @@ fn load_directory_configs(dir: &Path) -> Result<Config, Error> {
}

// Convert final merged PartialConfig to Config
Config::from_partial(merged_partial.expect("found_any ensures this is Some"))
Config::from_partial(
merged_partial.unwrap_or_else(|| unreachable!("the found_any guard above ensures Some")),
)
}

#[cfg(test)]
Expand Down
4 changes: 3 additions & 1 deletion lading/src/generator/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ impl BlockThrottle {
) -> Result<(), lading_throttle::Error> {
let tokens: NonZeroU32 = match self.mode {
ThrottleMode::Bytes => block_cache.peek_next_size(handle),
ThrottleMode::Blocks => NonZeroU32::new(1).expect("non-zero"),
ThrottleMode::Blocks => {
NonZeroU32::new(1).unwrap_or_else(|| unreachable!("1 is nonzero by construction"))
}
};
self.inner.wait_for(tokens).await
}
Expand Down
14 changes: 7 additions & 7 deletions lading/src/generator/file_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,31 +84,31 @@ pub enum Error {
}

fn default_max_depth() -> NonZeroUsize {
NonZeroUsize::new(10).expect("default max depth given was 0")
NonZeroUsize::new(10).unwrap_or_else(|| unreachable!("10 is nonzero by construction"))
}

fn default_max_sub_folders() -> NonZeroU32 {
NonZeroU32::new(5).expect("default max sub folders given was 0")
NonZeroU32::new(5).unwrap_or_else(|| unreachable!("5 is nonzero by construction"))
}

fn default_max_files() -> NonZeroU32 {
NonZeroU32::new(5).expect("default max files given was 0")
NonZeroU32::new(5).unwrap_or_else(|| unreachable!("5 is nonzero by construction"))
}

fn default_max_nodes() -> NonZeroUsize {
NonZeroUsize::new(100).expect("default max nodes given was 0")
NonZeroUsize::new(100).unwrap_or_else(|| unreachable!("100 is nonzero by construction"))
}

fn default_name_len() -> NonZeroUsize {
NonZeroUsize::new(8).expect("default name len given was 0")
NonZeroUsize::new(8).unwrap_or_else(|| unreachable!("8 is nonzero by construction"))
}

fn default_open_per_second() -> NonZeroU32 {
NonZeroU32::new(8).expect("default open per second given was 0")
NonZeroU32::new(8).unwrap_or_else(|| unreachable!("8 is nonzero by construction"))
}

fn default_rename_per_name() -> NonZeroU32 {
NonZeroU32::new(1).expect("default rename per second given was 0")
NonZeroU32::new(1).unwrap_or_else(|| unreachable!("1 is nonzero by construction"))
}

#[derive(Debug, Deserialize, Serialize, PartialEq, Clone)]
Expand Down
15 changes: 8 additions & 7 deletions lading/src/generator/process_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,32 +97,33 @@ pub enum Error {
}

fn default_max_depth() -> NonZeroU32 {
NonZeroU32::new(10).expect("default max depth given was 0")
NonZeroU32::new(10).unwrap_or_else(|| unreachable!("10 is nonzero by construction"))
}

// default to 100ms
fn default_process_sleep_ns() -> NonZeroU32 {
NonZeroU32::new(100_000_000).expect("default process sleep ns given was 0")
NonZeroU32::new(100_000_000)
.unwrap_or_else(|| unreachable!("100_000_000 is nonzero by construction"))
}

fn default_max_children() -> NonZeroU32 {
NonZeroU32::new(10).expect("default max children given was 0")
NonZeroU32::new(10).unwrap_or_else(|| unreachable!("10 is nonzero by construction"))
}

fn default_args_len() -> NonZeroUsize {
NonZeroUsize::new(10).expect("default args len given was 0")
NonZeroUsize::new(10).unwrap_or_else(|| unreachable!("10 is nonzero by construction"))
}

fn default_args_count() -> NonZeroU32 {
NonZeroU32::new(16).expect("default args count given was 0")
NonZeroU32::new(16).unwrap_or_else(|| unreachable!("16 is nonzero by construction"))
}

fn default_envs_len() -> NonZeroUsize {
NonZeroUsize::new(16).expect("default envs len given was 0")
NonZeroUsize::new(16).unwrap_or_else(|| unreachable!("16 is nonzero by construction"))
}

fn default_envs_count() -> NonZeroU32 {
NonZeroU32::new(10).expect("default envs count given was 0")
NonZeroU32::new(10).unwrap_or_else(|| unreachable!("10 is nonzero by construction"))
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
Expand Down
4 changes: 2 additions & 2 deletions lading/src/generator/tcp_rr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ use crate::neper::metrics::{self, ThreadMetrics};
use crate::neper::thread;

fn default_nonzero_u16() -> NonZeroU16 {
NonZeroU16::new(1).expect("1 is nonzero")
NonZeroU16::new(1).unwrap_or_else(|| unreachable!("1 is nonzero by construction"))
}

fn default_nonzero_usize() -> NonZeroUsize {
NonZeroUsize::new(1).expect("1 is nonzero")
NonZeroUsize::new(1).unwrap_or_else(|| unreachable!("1 is nonzero by construction"))
}

const fn default_true() -> bool {
Expand Down
3 changes: 2 additions & 1 deletion lading/src/generator/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ fn default_bind_addr() -> SocketAddr {

// https://stackoverflow.com/a/42610200
fn maximum_block_size() -> Byte {
Byte::from_u64_with_unit(65_507, Unit::B).expect("catastrophic programming bug")
Byte::from_u64_with_unit(65_507, Unit::B)
.unwrap_or_else(|| unreachable!("65_507 bytes is a representable Byte value"))
}

#[derive(Debug, Deserialize, Serialize, PartialEq, Clone)]
Expand Down
3 changes: 2 additions & 1 deletion lading/src/generator/unix_datagram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ fn default_parallel_connections() -> u16 {
// Mimic the belief of Datadog Agent, although correctly we should be reading
// sysctl values on Linux.
fn maximum_block_size() -> Byte {
Byte::from_u64_with_unit(8_192, Unit::B).expect("catastrophic programming bug")
Byte::from_u64_with_unit(8_192, Unit::B)
.unwrap_or_else(|| unreachable!("8_192 bytes is a representable Byte value"))
}

#[derive(Debug, Deserialize, Serialize, PartialEq, Clone)]
Expand Down
Loading