From ab182be622acb245db0adef58591978208bcdb2c Mon Sep 17 00:00:00 2001 From: Thomas Bertschinger Date: Wed, 2 Jul 2025 13:42:11 -0600 Subject: [PATCH] aya: `construct_debuglink_path()` should be infallible `construct_debuglink_path()` returns a `Result`, but it doesn't actually do anything that can fail. This means callers must do a useless `unwrap()` to get at the return value. This fixes the signature to reflect that the function is infallible. --- aya/src/programs/uprobe.rs | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/aya/src/programs/uprobe.rs b/aya/src/programs/uprobe.rs index 2ebb063d..a3d845d7 100644 --- a/aya/src/programs/uprobe.rs +++ b/aya/src/programs/uprobe.rs @@ -617,14 +617,11 @@ enum ResolveSymbolError { BuildIdMismatch(String), } -fn construct_debuglink_path( - filename: &[u8], - main_path: &Path, -) -> Result { +fn construct_debuglink_path(filename: &[u8], main_path: &Path) -> PathBuf { let filename_str = OsStr::from_bytes(filename); let debuglink_path = Path::new(filename_str); - let resolved_path = if debuglink_path.is_relative() { + if debuglink_path.is_relative() { // If the debug path is relative, resolve it against the parent of the main path main_path.parent().map_or_else( || PathBuf::from(debuglink_path), // Use original if no parent @@ -633,9 +630,7 @@ fn construct_debuglink_path( } else { // If the path is not relative, just use original PathBuf::from(debuglink_path) - }; - - Ok(resolved_path) + } } fn verify_build_ids<'a>( @@ -664,7 +659,7 @@ fn find_debug_path_in_object<'a>( symbol: &str, ) -> Result { match obj.gnu_debuglink() { - Ok(Some((filename, _))) => construct_debuglink_path(filename, main_path), + Ok(Some((filename, _))) => Ok(construct_debuglink_path(filename, main_path)), Ok(None) => Err(ResolveSymbolError::Unknown(symbol.to_string())), Err(err) => Err(ResolveSymbolError::Object(err)), } @@ -737,7 +732,7 @@ mod tests { let main_path = Path::new("/usr/lib/main_binary"); let expected = Path::new("/usr/lib/debug_info"); - let result = construct_debuglink_path(filename, main_path).unwrap(); + let result = construct_debuglink_path(filename, main_path); assert_eq!( result, expected, "The debug path should resolve relative to the main path's parent" @@ -750,7 +745,7 @@ mod tests { let main_path = Path::new("main_binary"); let expected = Path::new("debug_info"); - let result = construct_debuglink_path(filename, main_path).unwrap(); + let result = construct_debuglink_path(filename, main_path); assert_eq!( result, expected, "The debug path should be the original path as there is no parent" @@ -763,7 +758,7 @@ mod tests { let main_path = Path::new("/usr/lib/main_binary"); let expected = Path::new("/absolute/path/to/debug_info"); - let result = construct_debuglink_path(filename, main_path).unwrap(); + let result = construct_debuglink_path(filename, main_path); assert_eq!( result, expected, "The debug path should be the same as the input absolute path"