Skip to content

Commit

Permalink
Don't panic on non-zero status exit
Browse files Browse the repository at this point in the history
  • Loading branch information
alexheretic committed Jun 27, 2024
1 parent 6d66b20 commit 8c771c5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Support logging enabled when stderr is not a terminal or by setting env var `RUST_LOG`. E.g:
- `RUST_LOG=ab_av1=info` "info" level logs various progress results like sample encode info
- `RUST_LOG=ab_av1=debug` "debug" level logs include ffmpeg calls
* Don't panic on non-zero status exit.

# v0.7.14
* Fix bash completions of some filenames.
Expand Down
3 changes: 1 addition & 2 deletions src/command/print_completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ pub struct Args {
shell: Shell,
}

pub fn print_completions(Args { shell }: Args) -> anyhow::Result<()> {
pub fn print_completions(Args { shell }: Args) {
clap_complete::generate(
shell,
&mut crate::Command::command(),
"ab-av1",
&mut std::io::stdout(),
);
Ok(())
}
19 changes: 15 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod sample;
mod temporary;
mod vmaf;

use ::log::{error, LevelFilter};
use anyhow::anyhow;
use clap::Parser;
use futures::FutureExt;
Expand All @@ -30,11 +31,15 @@ enum Command {
}

#[tokio::main(flavor = "current_thread")]
async fn main() -> anyhow::Result<()> {
if !std::io::stderr().is_terminal() && env::var_os("RUST_LOG").is_none() {
async fn main() {
let stderr_term = std::io::stderr().is_terminal();
if !stderr_term && env::var_os("RUST_LOG").is_none() {
env::set_var("RUST_LOG", "ab_av1=info");
}
env_logger::init();
env_logger::builder()
.filter_level(LevelFilter::Off)
.parse_default_env()
.init();

let action = Command::parse();

Expand All @@ -59,7 +64,13 @@ async fn main() -> anyhow::Result<()> {
// Final cleanup. Samples are already deleted (if wished by the user) during `command::sample_encode::run`.
temporary::clean(keep).await;

out
if let Err(err) = out {
error!("{err}");
if stderr_term {
eprintln!("Error: {err}");
}
std::process::exit(1);
}
}

impl Command {
Expand Down

0 comments on commit 8c771c5

Please sign in to comment.