mirror of
https://github.com/arabianq/pipewire-soundpad.git
synced 2026-04-27 22:11:22 +00:00
🧹 refactor: replace unsafe unwraps in pipewire port parsing with safe destructuring (#34)
Replaced sequential unwraps on pipewire properties ("node.id", "port.id", "port.name")
with an `if let` and `and_then()` pattern in `src/utils/pipewire.rs`. This provides
safety against daemon crashes when properties are missing or malformed by silently
returning instead of panicking.
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
498d0d25af
commit
d6effc972e
+12
-10
@@ -57,17 +57,19 @@ fn parse_global_object(
|
||||
};
|
||||
// Check if the object is a port
|
||||
} else if props.get("port.direction").is_some() {
|
||||
let node_id = props.get("node.id").unwrap().parse::<u32>().unwrap();
|
||||
let port_id = props.get("port.id").unwrap().parse::<u32>().unwrap();
|
||||
let port_name = props.get("port.name").unwrap();
|
||||
if let (Some(node_id), Some(port_id), Some(port_name)) = (
|
||||
props.get("node.id").and_then(|id| id.parse::<u32>().ok()),
|
||||
props.get("port.id").and_then(|id| id.parse::<u32>().ok()),
|
||||
props.get("port.name"),
|
||||
) {
|
||||
let port = Port {
|
||||
node_id,
|
||||
port_id,
|
||||
name: port_name.to_string(),
|
||||
};
|
||||
|
||||
let port = Port {
|
||||
node_id,
|
||||
port_id,
|
||||
name: port_name.to_string(),
|
||||
};
|
||||
|
||||
return (None, Some(port));
|
||||
return (None, Some(port));
|
||||
}
|
||||
}
|
||||
}
|
||||
(None, None)
|
||||
|
||||
Reference in New Issue
Block a user