Skip to content

Commit

Permalink
First batch of unwrap()'s removed (mostly in re_types)
Browse files Browse the repository at this point in the history
  • Loading branch information
Artxiom committed May 13, 2024
1 parent 3a42904 commit d92f36b
Show file tree
Hide file tree
Showing 87 changed files with 313 additions and 308 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ missing_errors_doc = "allow"
# This would be nice to enable, but we have way too many unwraps right now 😭
# Enabling this lint in 2023-04-27 yielded 556 hits.
# Enabling this lint in 2023-09-23 yielded 352 hits
unwrap_used = "allow"
unwrap_used = "warn"

[patch.crates-io]
# Try to avoid patching crates! It prevents us from publishing the crates on crates.io.
Expand Down
6 changes: 3 additions & 3 deletions crates/re_analytics/examples/end_to_end.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ use re_analytics::Event;
use re_analytics::Properties;
use re_analytics::{Analytics, AnalyticsEvent};

fn main() -> ! {
fn main() -> Result<(), Box<dyn std::error::Error>> {
re_log::setup_logging();

let analytics = Analytics::new(Duration::from_secs(3)).unwrap();
let analytics = Analytics::new(Duration::from_secs(3))?;
let application_id = "end_to_end_example".to_owned();
let recording_id = uuid::Uuid::new_v4().to_string();

println!("any non-empty line written here will be sent as an analytics datapoint");
loop {
let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
std::io::stdin().read_line(&mut input)?;

let input = input.trim();
if !input.is_empty() {
Expand Down
4 changes: 3 additions & 1 deletion crates/re_analytics/src/native/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ impl Config {
}

pub fn config_dir(&self) -> &Path {
self.config_file_path.parent().unwrap()
self.config_file_path
.parent()
.expect("config file has no parent")
}

pub fn config_file(&self) -> &Path {
Expand Down
4 changes: 2 additions & 2 deletions crates/re_build_info/src/build_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ fn crate_version_from_build_info_string() {

{
let expected_crate_version = build_info.version;
let crate_version = CrateVersion::try_parse_from_build_info_string(build_info_str).unwrap();
let crate_version = CrateVersion::try_parse_from_build_info_string(build_info_str);

assert_eq!(expected_crate_version, crate_version);
assert_eq!(Ok(expected_crate_version), crate_version);
}
}
2 changes: 1 addition & 1 deletion crates/re_build_tools/src/hashing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{rerun_if_changed, rerun_if_changed_or_doesnt_exist};
fn encode_hex(bytes: &[u8]) -> String {
let mut s = String::with_capacity(bytes.len() * 2);
for &b in bytes {
write!(&mut s, "{b:02x}").unwrap();
write!(&mut s, "{b:02x}").expect("writing to string should never fail");
}
s
}
Expand Down
19 changes: 13 additions & 6 deletions crates/re_data_store/benches/gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use itertools::Itertools;
use re_data_store::{
DataStore, DataStoreConfig, GarbageCollectionOptions, GarbageCollectionTarget,
};
use re_log::ResultExt;
use re_log_types::{
build_frame_nr, build_log_time, DataRow, DataTable, EntityPath, RowId, TableId, Time, TimePoint,
};
Expand Down Expand Up @@ -156,8 +157,9 @@ where
for _ in 0..NUM_ROWS_PER_ENTITY_PATH {
#[allow(clippy::needless_range_loop)] // readability
for i in 0..NUM_ENTITY_PATHS {
let row = rows_per_table[i].next().unwrap();
store.insert_row(&row.unwrap()).unwrap();
if let Some(Ok(row)) = rows_per_table[i].next() {
store.insert_row(&row).ok_or_log_error();
}
}
}

Expand All @@ -176,7 +178,7 @@ where
{
let mut table = DataTable::from_rows(
TableId::ZERO,
(0..NUM_ROWS_PER_ENTITY_PATH).map(move |i| {
(0..NUM_ROWS_PER_ENTITY_PATH).filter_map(move |i| {
DataRow::from_component_batches(
RowId::new(),
timegen(i),
Expand All @@ -186,14 +188,19 @@ where
.iter()
.map(|batch| batch as &dyn ComponentBatch),
)
.unwrap()
.ok_or_log_error()
}),
);

// Do a serialization roundtrip to pack everything in contiguous memory.
if packed {
let (schema, columns) = table.serialize().unwrap();
table = DataTable::deserialize(TableId::ZERO, &schema, &columns).unwrap();
if let Some(t) = table
.serialize()
.and_then(|(schema, columns)| DataTable::deserialize(TableId::ZERO, &schema, &columns))
.ok_or_log_error()
{
table = t;
}
}

table.compute_all_size_bytes();
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/re_types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ version.workspace = true
[lints]
workspace = true


[package.metadata.docs.rs]
all-features = false
no-default-features = true
Expand Down
3 changes: 1 addition & 2 deletions crates/re_types/src/blueprint/components/active_tab.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions crates/re_types/src/blueprint/components/included_content.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions crates/re_types/src/blueprint/components/query_expression.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions crates/re_types/src/blueprint/components/space_view_class.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions crates/re_types/src/components/annotation_context.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions crates/re_types/src/components/blob.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crates/re_types/src/components/half_sizes2d.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crates/re_types/src/components/half_sizes3d.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions crates/re_types/src/components/line_strip2d.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions crates/re_types/src/components/line_strip3d.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions crates/re_types/src/components/media_type.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions crates/re_types/src/components/name.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crates/re_types/src/components/pinhole_projection.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crates/re_types/src/components/position2d.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crates/re_types/src/components/position3d.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crates/re_types/src/components/range1d.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d92f36b

Please sign in to comment.