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:
@@ -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;
|
||||
|
||||
@@ -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)]
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user