fix: remove unwraps and add some error handling.

This commit is contained in:
Didier Slof 2023-05-08 00:43:42 +02:00
parent 92833c21ce
commit 25e63c2aae
Signed by: didier
GPG key ID: 01E71F18AA4398E5

View file

@ -27,7 +27,13 @@ fn main() {
.collect::<Vec<_>>();
info!("Found {} file(s) to be processed.", input_files.len());
let mut success_count = 0;
for file in input_files {
let mut fail = |job: &TranscodeJob, remarks: &str| {
error!("Failed to process file {}: {}", job.input, remarks);
};
let mut output_path = file.clone();
output_path.set_extension(&config.ffmpeg.output.format);
let output_path = PathBuf::from(&config.files.output_path).join(output_path.file_name().unwrap()); // TODO: This is a bit of a mess.
@ -43,15 +49,34 @@ fn main() {
}
info!("Processing file {}.", job.input);
let mut child = job.run(&config.ffmpeg).unwrap();
let mut child = match job.run(&config.ffmpeg) {
Ok(child) => child,
Err(e) => {
fail(&job, &format!("Failed to start ffmpeg process: {}", e));
continue;
}
};
if (config.ffmpeg.process.niceness.unwrap_or(0)) > 0 {
renice(child.id(), config.ffmpeg.process.niceness.unwrap_or(0))
.expect("Failed to renice process.");
match renice(child.id(), config.ffmpeg.process.niceness.unwrap()) {
Ok(_) => {},
Err(e) => {
error!("Failed to renice ffmpeg process: {}", e);
}
}
}
if let Err(e) = child.wait() {
fail(&job, &format!("Failed to wait for ffmpeg process: {}", e));
continue;
}
child.wait().expect("Failed to wait for process.");
// TODO: Cleanup
info!("Finished processing file {}.", job.input);
success_count += 1;
}
info!("Finished processing {} file(s).", success_count);
}
fn setup_logger(config: &configuration::Config) {