From feed5ec7de4dcd620a71adfae5d0ce7daf5b8d1e Mon Sep 17 00:00:00 2001 From: astar76 Date: Tue, 1 Dec 2026 21:36:03 -0600 Subject: [PATCH] S002: timeout errors as user cards Co-Authored-By: Claude Sonnet 5.5 --- docs/PROGRESS.md | 1 + docs/tests/S002-outbound-timeouts.md | 4 +++- src/commands/media/ffmpeg.rs | 2 +- src/commands/music/ytdl.rs | 2 +- src/commands/tools/virus.rs | 2 +- 5 files changed, 7 insertions(+), 4 deletions(-) diff --git a/docs/PROGRESS.md b/docs/PROGRESS.md index fb1dc5e..ee09afd 100644 --- a/docs/PROGRESS.md +++ b/docs/PROGRESS.md @@ -24,3 +24,4 @@ One entry per session, newest last, ≤ 15 lines: done, verified how, not done, ## 2026-12-01 — S002 outbound timeouts - Done: audit found most spawns and HTTP calls already limited. Fixed: `ffmpeg::probe` (no limit), `ffmpeg::inspect` (no kill), music stream and peaks (ffmpeg `-rw_timeout` 20 s idle, peaks read idle 30 s). Helper stays `download::tools::run_lines`. - Verified: `cargo check` only. Not done: `bail_user!` rewrite of the plain timeout strings; not tested. +- S002 follow-up: timeout texts reworded in plain words (`ffmpeg::run`, `ytdl::extract`, VirusTotal wait). They are NOT `bail_user!`: those helpers return `Result<_, String>` (bail_user needs the command error type), and every caller already shows the string as a "❌ ..." reply. `download/tools.rs` already uses `DlError::user` cards. Turning the helpers into `UserError` would touch many callers; left for later. diff --git a/docs/tests/S002-outbound-timeouts.md b/docs/tests/S002-outbound-timeouts.md index a548c4a..7788924 100644 --- a/docs/tests/S002-outbound-timeouts.md +++ b/docs/tests/S002-outbound-timeouts.md @@ -26,10 +26,12 @@ Not changed: timeouts keep their existing card text ("took too long" strings); n | 7 | MED | `fetch_limited` against a 50 MB file | returns None at the size cap | by hand | — | | 8 | LOW | `rg "Command::new" src` | every non-test spawn has a timeout or idle limit | by hand | — | | 9 | LOW | Normal song plays with `-rw_timeout` | plays, seek works | by hand | — | +| 10 | MED | Make `/convert` run past its limit | reply says "The conversion took too long ..." | by hand | — | +| 11 | LOW | Make a `/play` lookup time out | reply says "The song lookup took too long ..." | by hand | — | ## Needs A test server or local slow HTTP server (python), a Discord test guild; never the real token on this PC. ## Doubts - `-rw_timeout` on HTTP inputs: assumed supported by the server's ffmpeg build (HTTP protocol option, µs). Verify song playback and that a stall really ends the process. -- Timeout messages are not all `bail_user!` cards; some are plain strings shown by callers. +- Timeout messages from string-returning helpers (`ffmpeg::run`, `ytdl::extract`, `make_song`, VirusTotal wait) are plain strings that callers show as a "❌ ..." reply, not `bail_user!`: the helpers can't return `UserError`. Check the text reads well in each (checks 10-11). diff --git a/src/commands/media/ffmpeg.rs b/src/commands/media/ffmpeg.rs index fa2def6..19bde18 100644 --- a/src/commands/media/ffmpeg.rs +++ b/src/commands/media/ffmpeg.rs @@ -33,7 +33,7 @@ pub async fn run(args: &[String], limit: Duration) -> Result<(), String> { cmd.args(["-hide_banner", "-loglevel", "error", "-nostdin", "-y"]).args(args).stdin(Stdio::null()).stdout(Stdio::null()).stderr(Stdio::piped()).kill_on_drop(true); let child = cmd.spawn().map_err(|e| format!("ffmpeg isn't installed or can't start ({e})"))?; match tokio::time::timeout(limit, child.wait_with_output()).await { - Err(_) => Err("that took too long".to_string()), + Err(_) => Err("The conversion took too long (slow connection or a very big file). Try a smaller file or lower quality.".to_string()), Ok(Err(e)) => Err(e.to_string()), Ok(Ok(out)) if out.status.success() => Ok(()), Ok(Ok(out)) => { diff --git a/src/commands/music/ytdl.rs b/src/commands/music/ytdl.rs index 86dcd44..831d539 100644 --- a/src/commands/music/ytdl.rs +++ b/src/commands/music/ytdl.rs @@ -184,7 +184,7 @@ pub async fn extract(query: &str, mode: Mode) -> Result { } }; cmd.arg("--").arg(query).stdin(Stdio::null()).kill_on_drop(true); - let out = tokio::time::timeout(Duration::from_secs(limit), cmd.output()).await.map_err(|_| "That took too long — try again.".to_string())?.map_err(|e| format!("yt-dlp can't start ({e})"))?; + let out = tokio::time::timeout(Duration::from_secs(limit), cmd.output()).await.map_err(|_| "The song lookup took too long (YouTube or the connection is slow). Try again in a bit.".to_string())?.map_err(|e| format!("yt-dlp can't start ({e})"))?; if !out.status.success() { return Err(clean_error(&String::from_utf8_lossy(&out.stderr))); } diff --git a/src/commands/tools/virus.rs b/src/commands/tools/virus.rs index b09630c..0bd2715 100644 --- a/src/commands/tools/virus.rs +++ b/src/commands/tools/virus.rs @@ -70,7 +70,7 @@ async fn wait(state: &State, key: &str, analysis: &str, after: &str) -> Result Result {