Skip to content

Commit

Permalink
Input: Clarify YoutubeDl error if command missing (#160)
Browse files Browse the repository at this point in the history
Converts any `io::ErrorKind::NotFound` from `TokioCommand` into a more useful string for users, e.g., `"could not find executable 'yt-dlp' on path"`.

Tested using `cargo make ready`.
  • Loading branch information
FelixMcFelix committed Nov 20, 2023
1 parent ed4be7c commit 53ebc3c
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/input/sources/ytdl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use reqwest::{
header::{HeaderMap, HeaderName, HeaderValue},
Client,
};
use std::error::Error;
use std::{error::Error, io::ErrorKind};
use symphonia_core::io::MediaSource;
use tokio::process::Command;

Expand Down Expand Up @@ -63,7 +63,13 @@ impl YoutubeDl {
.args(ytdl_args)
.output()
.await
.map_err(|e| AudioStreamError::Fail(Box::new(e)))?;
.map_err(|e| {
AudioStreamError::Fail(if e.kind() == ErrorKind::NotFound {
format!("could not find executable '{}' on path", self.program).into()
} else {
Box::new(e)
})
})?;

// NOTE: must be mut for simd-json.
#[allow(clippy::unnecessary_mut_passed)]
Expand Down Expand Up @@ -157,4 +163,12 @@ mod tests {
async fn ytdl_backward_seek_correct() {
backward_seek_correct(|| YoutubeDl::new(Client::new(), YTDL_TARGET.into())).await;
}

#[tokio::test]
#[ntest::timeout(20_000)]
async fn fake_exe_errors() {
let mut ytdl = YoutubeDl::new_ytdl_like("yt-dlq", Client::new(), YTDL_TARGET.into());

assert!(ytdl.aux_metadata().await.is_err());
}
}

0 comments on commit 53ebc3c

Please sign in to comment.