Skip to content

Commit

Permalink
Merge pull request #13 from gabrielmagno/bugfix/improve-device-handling
Browse files Browse the repository at this point in the history
Ignores a device that returns an error while discovering devices
  • Loading branch information
gabrielmagno authored Aug 20, 2023
2 parents b86f37e + d171e5f commit 6b62b24
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
21 changes: 12 additions & 9 deletions src/devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,21 @@ impl Render {

let mut renders = Vec::new();

while let Some(device) = devices
.try_next()
while let Some(result) = devices
.next()
.await
.map_err(Error::DevicesNextDeviceError)?
{
debug!("Found device: {}", format_device!(device));
match Self::from_device(device).await {
Some(render) => {
renders.push(render);
match result {
Ok(device) => {
debug!("Found device: {}", format_device!(device));
if let Some(render) = Self::from_device(device).await {
renders.push(render);
};
}
None => {}
};
Err(e) => {
debug!("A device returned error while discovering it: {}", e);
}
}
}

Ok(renders)
Expand Down
4 changes: 0 additions & 4 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ use std::fmt;
pub enum Error {
/// An error occurred while discovering devices
DevicesDiscoverFail(rupnp::Error),
/// An error occurred while iterating over discovered devices
DevicesNextDeviceError(rupnp::Error),
/// An error occurred while parsing a device URL
DevicesUrlParseError(String),
/// An error occurred while parsing and creating a device
Expand All @@ -34,7 +32,6 @@ impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::DevicesDiscoverFail(err) => write!(f, "Failed to discover devices: {}", err),
Error::DevicesNextDeviceError(err) => write!(f, "Failed to get next device: {}", err),
Error::DevicesUrlParseError(url) => write!(f, "Failed to parse URL '{}'", url),
Error::DevicesCreateError(url, err) => write!(
f,
Expand Down Expand Up @@ -77,7 +74,6 @@ impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::DevicesDiscoverFail(err) => Some(err),
Error::DevicesNextDeviceError(err) => Some(err),
Error::DevicesCreateError(_, err) => Some(err),
Error::StreamingRemoteRenderConnectFail(_, err) => Some(err),
Error::StreamingIdentifyLocalAddressError(err) => Some(err),
Expand Down

0 comments on commit 6b62b24

Please sign in to comment.