mirror of
https://github.com/arabianq/pipewire-soundpad.git
synced 2026-04-28 06:21:23 +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
@@ -57,10 +57,11 @@ fn parse_global_object(
|
|||||||
};
|
};
|
||||||
// Check if the object is a port
|
// Check if the object is a port
|
||||||
} else if props.get("port.direction").is_some() {
|
} else if props.get("port.direction").is_some() {
|
||||||
let node_id = props.get("node.id").unwrap().parse::<u32>().unwrap();
|
if let (Some(node_id), Some(port_id), Some(port_name)) = (
|
||||||
let port_id = props.get("port.id").unwrap().parse::<u32>().unwrap();
|
props.get("node.id").and_then(|id| id.parse::<u32>().ok()),
|
||||||
let port_name = props.get("port.name").unwrap();
|
props.get("port.id").and_then(|id| id.parse::<u32>().ok()),
|
||||||
|
props.get("port.name"),
|
||||||
|
) {
|
||||||
let port = Port {
|
let port = Port {
|
||||||
node_id,
|
node_id,
|
||||||
port_id,
|
port_id,
|
||||||
@@ -70,6 +71,7 @@ fn parse_global_object(
|
|||||||
return (None, Some(port));
|
return (None, Some(port));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
(None, None)
|
(None, None)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user