From 53ebc3c637137c6d8b383494e8bbdde31a81cc07 Mon Sep 17 00:00:00 2001 From: Kyle Simpson Date: Tue, 31 Jan 2023 18:04:04 +0000 Subject: [PATCH] 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`. --- src/input/sources/ytdl.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/input/sources/ytdl.rs b/src/input/sources/ytdl.rs index f34eb6925..a338a374b 100644 --- a/src/input/sources/ytdl.rs +++ b/src/input/sources/ytdl.rs @@ -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()); + } }