Input: Clarify YoutubeDl error if command missing (#160)

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`.
This commit is contained in:
Kyle Simpson
2023-01-31 18:04:04 +00:00
parent ed4be7c607
commit 53ebc3c637

View File

@@ -12,7 +12,7 @@ use reqwest::{
header::{HeaderMap, HeaderName, HeaderValue}, header::{HeaderMap, HeaderName, HeaderValue},
Client, Client,
}; };
use std::error::Error; use std::{error::Error, io::ErrorKind};
use symphonia_core::io::MediaSource; use symphonia_core::io::MediaSource;
use tokio::process::Command; use tokio::process::Command;
@@ -63,7 +63,13 @@ impl YoutubeDl {
.args(ytdl_args) .args(ytdl_args)
.output() .output()
.await .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. // NOTE: must be mut for simd-json.
#[allow(clippy::unnecessary_mut_passed)] #[allow(clippy::unnecessary_mut_passed)]
@@ -157,4 +163,12 @@ mod tests {
async fn ytdl_backward_seek_correct() { async fn ytdl_backward_seek_correct() {
backward_seek_correct(|| YoutubeDl::new(Client::new(), YTDL_TARGET.into())).await; 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());
}
} }