aboutsummaryrefslogtreecommitdiffstats
path: root/src/commands/math.rs
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-11-04 01:11:50 +0100
committersalmonik <salmonik@tuta.io>2026-11-04 01:11:50 +0100
commitfd93334a21907f959018e1b1f5df747a98d186c8 (patch)
tree259e595a570b42a5ea082f596e1cb97e5011cfba /src/commands/math.rs
parenthttp: add connect and request timeouts (diff)
downloadsenator-sperma-fd93334a21907f959018e1b1f5df747a98d186c8.tar.gz
senator-sperma-fd93334a21907f959018e1b1f5df747a98d186c8.zip
processes: add timeouts and keep decoding off the runtime
Diffstat (limited to 'src/commands/math.rs')
-rw-r--r--src/commands/math.rs19
1 files changed, 14 insertions, 5 deletions
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(
57 return Ok(()); 57 return Ok(());
58 } 58 }
59 59
60 let output = tokio::process::Command::new("qalc") 60 let output = match tokio::time::timeout(
61 .arg(&equation) 61 std::time::Duration::from_secs(5),
62 .output() 62 tokio::process::Command::new("qalc")
63 .await 63 .arg(&equation)
64 .map_err(|e| Error::Custom(lang::fmt_math_qalc_err(&e)))?; 64 .output(),
65 )
66 .await
67 {
68 Ok(result) => result.map_err(|e| Error::Custom(lang::fmt_math_qalc_err(&e)))?,
69 Err(_) => {
70 ctx.say(lang::L_MATH_NO_RESULT).await?;
71 return Ok(());
72 }
73 };
65 74
66 let result = String::from_utf8_lossy(&output.stdout).trim().to_string(); 75 let result = String::from_utf8_lossy(&output.stdout).trim().to_string();
67 if result.is_empty() { 76 if result.is_empty() {