Skip to content

Commit 4f47c6a

Browse files
authored
ref: Forbid unwrap except in tests and benches (#58)
1 parent c9841a5 commit 4f47c6a

File tree

7 files changed

+12
-8
lines changed

7 files changed

+12
-8
lines changed

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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ edition = "2021"
1313
[features]
1414
uuid = ["dep:uuid"]
1515

16+
[lints.clippy]
17+
unwrap-used = "warn"
18+
1619
[dependencies]
1720
serde = { version = "1.0.219", features = ["derive"] }
1821
serde_json = "1.0.140"

benches/proguard_mapping.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(clippy::unwrap_used)]
12
use criterion::{black_box, criterion_group, criterion_main, Criterion};
23
use proguard::{ProguardCache, ProguardMapper, ProguardMapping};
34

benches/proguard_parsing.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(clippy::unwrap_used)]
12
use criterion::{black_box, criterion_group, criterion_main, Criterion};
23
use proguard::{ProguardCache, ProguardMapper, ProguardMapping};
34

clippy.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
allow-unwrap-in-tests = true

src/cache/debug.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ impl ClassDebug<'_, '_> {
1515
fn obfuscated_name(&self) -> &str {
1616
self.cache
1717
.read_string(self.raw.obfuscated_name_offset)
18-
.unwrap()
18+
.unwrap_or("<unknown>")
1919
}
2020

2121
fn original_name(&self) -> &str {
2222
self.cache
2323
.read_string(self.raw.original_name_offset)
24-
.unwrap()
24+
.unwrap_or("<unknown>")
2525
}
2626

2727
fn file_name(&self) -> Option<&str> {
@@ -76,13 +76,13 @@ impl MemberDebug<'_, '_> {
7676
fn obfuscated_name(&self) -> &str {
7777
self.cache
7878
.read_string(self.raw.obfuscated_name_offset)
79-
.unwrap()
79+
.unwrap_or("<unknown>")
8080
}
8181

8282
fn original_name(&self) -> &str {
8383
self.cache
8484
.read_string(self.raw.original_name_offset)
85-
.unwrap()
85+
.unwrap_or("<unknown>")
8686
}
8787

8888
fn original_endline(&self) -> Option<u32> {

src/stacktrace.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,11 @@ fn parse_stacktrace(content: &str) -> Option<StackTrace<'_>> {
129129
if let Some(frame) = parse_frame(line) {
130130
current.frames.push(frame);
131131
} else if let Some(line) = line.strip_prefix("Caused by: ") {
132-
current.cause = Some(Box::new(StackTrace {
132+
current = current.cause.insert(Box::new(StackTrace {
133133
exception: parse_throwable(line),
134134
frames: vec![],
135135
cause: None,
136136
}));
137-
// We just set the `cause` so it's safe to unwrap here
138-
current = current.cause.as_deref_mut().unwrap();
139137
}
140138
}
141139

0 commit comments

Comments
 (0)