Skip to content

Commit

Permalink
Migrate to sysexits
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
  • Loading branch information
SUPERCILEX committed Oct 4, 2022
1 parent b9d89e6 commit 8bb420f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ clap = { version = "4.0.9", features = ["derive", "wrap_help"] }
clap-num = "1.0.0"
clap-verbosity-flag = "2.0.0"
error-stack = "0.2.1"
exitcode = "1.1.2"
# TODO use the real itoa once https://github.com/dtolnay/itoa/pull/34 goes through
itoa-const = "1.0.1"
log = { version = "0.4.17", features = ["release_max_level_info"] }
Expand All @@ -25,6 +24,7 @@ rand = { version = "0.8.5", default-features = false }
rand_distr = "0.4.3"
rand_xoshiro = "0.6.0"
simple_logger = { version = "2.3.0", default-features = false, features = ["colors"] }
sysexits = "0.3.2"
thiserror = "1.0.37"
tokio = { version = "1.21.2", features = ["rt"] }
tracing = { version = "0.1.36", features = ["release_max_level_off", "log"] }
Expand Down
4 changes: 2 additions & 2 deletions src/core/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ pub async fn run(
.await
.into_report()
.change_context(Error::TaskJoin)
.attach(ExitCode::from(u8::try_from(exitcode::SOFTWARE).unwrap()))?
.attach(ExitCode::from(sysexits::ExitCode::Software))?
.change_context(Error::Io)
.attach(ExitCode::from(u8::try_from(exitcode::IOERR).unwrap()))?;
.attach(ExitCode::from(sysexits::ExitCode::IoErr))?;
#[cfg(dry_run)]
let outcome = task;

Expand Down
12 changes: 6 additions & 6 deletions src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
)]

use std::{
cmp::max, fs::create_dir_all, io::Write, num::NonZeroUsize, path::PathBuf,
process::ExitCode, thread,
cmp::max, fs::create_dir_all, io::Write, num::NonZeroUsize, path::PathBuf, process::ExitCode,
thread,
};

use error_stack::{IntoReport, Report, Result, ResultExt};
Expand Down Expand Up @@ -169,14 +169,14 @@ fn validated_options(generator: Generator) -> Result<Configuration, Error> {
.into_report()
.attach_printable_lazy(|| format!("Failed to create directory {:?}", generator.root_dir))
.change_context(Error::InvalidEnvironment)
.attach(ExitCode::from(u8::try_from(exitcode::IOERR).unwrap()))?;
.attach(ExitCode::from(sysexits::ExitCode::IoErr))?;
if generator
.root_dir
.read_dir()
.into_report()
.attach_printable_lazy(|| format!("Failed to read directory {:?}", generator.root_dir))
.change_context(Error::InvalidEnvironment)
.attach(ExitCode::from(u8::try_from(exitcode::IOERR).unwrap()))?
.attach(ExitCode::from(sysexits::ExitCode::IoErr))?
.count()
!= 0
{
Expand All @@ -185,7 +185,7 @@ fn validated_options(generator: Generator) -> Result<Configuration, Error> {
"The root directory {:?} must be empty.",
generator.root_dir
))
.attach(ExitCode::from(u8::try_from(exitcode::DATAERR).unwrap()));
.attach(ExitCode::from(sysexits::ExitCode::DataErr));
}

let num_files = generator.num_files_with_ratio.num_files.get() as f64;
Expand Down Expand Up @@ -323,7 +323,7 @@ fn run_generator(config: Configuration) -> Result<GeneratorStats, Error> {
.build()
.into_report()
.change_context(Error::RuntimeCreation)
.attach(ExitCode::from(u8::try_from(exitcode::OSERR).unwrap()))?;
.attach(ExitCode::from(sysexits::ExitCode::OsErr))?;

event!(Level::INFO, config = ?config, "Starting config");
runtime.block_on(run_generator_async(config, parallelism))
Expand Down

0 comments on commit 8bb420f

Please sign in to comment.