fix: abort if ffmpeg process errors

This commit is contained in:
uku 2025-05-19 18:58:06 +02:00
parent c0049cbb8d
commit 0475c52529
Signed by: uku
SSH key fingerprint: SHA256:4P0aN6M8ajKukNi6aPOaX0LacanGYtlfjmN+m/sHY/o

View file

@ -3,7 +3,8 @@ use std::{
process::Stdio, process::Stdio,
}; };
use color_eyre::eyre::{ContextCompat, Result}; use color_eyre::eyre::{ContextCompat, Result, bail};
use futures::channel::oneshot;
use relm4::{ use relm4::{
Sender, Sender,
tokio::{ tokio::{
@ -136,11 +137,10 @@ pub async fn convert_video(
let mut reader = BufReader::new(stdout).lines(); let mut reader = BufReader::new(stdout).lines();
// make sure the process is actually started and awaited // make sure the process is actually started and awaited
let (tx, rx) = oneshot::channel();
tokio::spawn(async move { tokio::spawn(async move {
child tx.send(child.wait().await)
.wait() .expect("could not send exit status");
.await
.expect("ffmpeg process encountered an error");
}); });
while let Some(line) = reader.next_line().await? { while let Some(line) = reader.next_line().await? {
@ -157,5 +157,10 @@ pub async fn convert_video(
} }
} }
let status = rx.await??;
if !status.success() {
bail!("ffmpeg process errored: {status}");
}
Ok(out_path) Ok(out_path)
} }