Skip to content

Commit be9a393

Browse files
authored
Merge pull request #997 from WhyNotHugo/avoid-unwrap-disco
Avoid crash when Avahi is not available
2 parents 6097d53 + c4af90f commit be9a393

3 files changed

Lines changed: 11 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3636
- [playback] Adhere to ReplayGain spec when calculating gain normalisation factor.
3737
- [playback] `alsa`: Use `--volume-range` overrides for softvol controls
3838
- [connect] Don't panic when activating shuffle without previous interaction.
39+
- [main] Fix crash when built with Avahi support but Avahi is locally unavailable.
3940

4041
### Removed
4142
- [playback] `alsamixer`: previously deprecated option `mixer-card` has been removed.

discovery/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ impl Builder {
111111
None,
112112
port,
113113
&["VERSION=1.0", "CPath=/"],
114-
)
115-
.unwrap();
114+
).map_err(|e| Error::DnsSdError(io::Error::new(io::ErrorKind::Unsupported, e)))?;
116115

117116
} else {
118117
let responder = libmdns::Responder::spawn(&tokio::runtime::Handle::current())?;

src/main.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,19 +1581,15 @@ async fn main() {
15811581

15821582
if setup.enable_discovery {
15831583
let device_id = setup.session_config.device_id.clone();
1584-
1585-
discovery = match librespot::discovery::Discovery::builder(device_id)
1584+
match librespot::discovery::Discovery::builder(device_id)
15861585
.name(setup.connect_config.name.clone())
15871586
.device_type(setup.connect_config.device_type)
15881587
.port(setup.zeroconf_port)
15891588
.launch()
15901589
{
1591-
Ok(d) => Some(d),
1592-
Err(e) => {
1593-
error!("Discovery Error: {}", e);
1594-
exit(1);
1595-
}
1596-
}
1590+
Ok(d) => discovery = Some(d),
1591+
Err(err) => warn!("Could not initialise discovery: {}.", err),
1592+
};
15971593
}
15981594

15991595
if let Some(credentials) = setup.credentials {
@@ -1606,6 +1602,11 @@ async fn main() {
16061602
)
16071603
.fuse(),
16081604
);
1605+
} else if discovery.is_none() {
1606+
error!(
1607+
"Discovery is unavailable and no credentials provided. Authentication is not possible."
1608+
);
1609+
exit(1);
16091610
}
16101611

16111612
loop {

0 commit comments

Comments
 (0)