Skip to content

Commit b9bce36

Browse files
d-e-s-oinsearchoflosttime
authored andcommitted
libbpf-cargo: Refactor stem extraction error handling
The way we deal with errors when working with the file stem of a path is hard to understand and make sense of. Shorten it by making better use of anyhow's features. Signed-off-by: Daniel Müller <deso@posteo.net>
1 parent bb0e282 commit b9bce36

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

libbpf-cargo/src/build.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,16 +166,16 @@ fn compile(debug: bool, objs: &[UnprocessedObj], clang: &Path, target_dir: &Path
166166
};
167167

168168
for obj in objs {
169-
let dest_name = if let Some(f) = obj.path.file_stem() {
170-
let mut stem = f.to_os_string();
171-
stem.push(".o");
172-
stem
173-
} else {
174-
bail!(
169+
let stem = obj.path.file_stem().with_context(|| {
170+
format!(
175171
"Could not calculate destination name for obj={}",
176172
obj.path.display()
177-
);
178-
};
173+
)
174+
})?;
175+
176+
let mut dest_name = stem.to_os_string();
177+
dest_name.push(".o");
178+
179179
let mut dest_path = obj.out.to_path_buf();
180180
dest_path.push(&dest_name);
181181
fs::create_dir_all(&obj.out)?;

0 commit comments

Comments
 (0)