From fd93334a21907f959018e1b1f5df747a98d186c8 Mon Sep 17 00:00:00 2001 From: salmonik Date: Wed, 4 Nov 2026 01:11:50 +0100 Subject: processes: add timeouts and keep decoding off the runtime --- src/commands/math.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src/commands/math.rs') diff --git a/src/commands/math.rs b/src/commands/math.rs index 43a7de8..25ddaab 100644 --- a/src/commands/math.rs +++ b/src/commands/math.rs @@ -57,11 +57,20 @@ pub async fn math( return Ok(()); } - let output = tokio::process::Command::new("qalc") - .arg(&equation) - .output() - .await - .map_err(|e| Error::Custom(lang::fmt_math_qalc_err(&e)))?; + let output = match tokio::time::timeout( + std::time::Duration::from_secs(5), + tokio::process::Command::new("qalc") + .arg(&equation) + .output(), + ) + .await + { + Ok(result) => result.map_err(|e| Error::Custom(lang::fmt_math_qalc_err(&e)))?, + Err(_) => { + ctx.say(lang::L_MATH_NO_RESULT).await?; + return Ok(()); + } + }; let result = String::from_utf8_lossy(&output.stdout).trim().to_string(); if result.is_empty() { -- cgit v1.2.3