From d5820bb20a30591de474026d07d2b793adcd1226 Mon Sep 17 00:00:00 2001 From: rvcas Date: Mon, 27 Nov 2023 21:48:56 -0500 Subject: [PATCH] fix: restore printing of some error messages We rely on some errors to just bubble up and get printed. By matching on result at the top level like this we blocked some error messages from being able to be printed. For me this showed up when `cargo run -- new thing/thing` printed nothing even when there was an existing `thing` folder. It has already been the pattern for sometime for some subcommands to handle calling process::exit(1) in situations where it needs to handle error reporting more specially. It may seem lame, hacky, or repetitive but it's easy to maintain and read. --- crates/aiken/src/cmd/blueprint/address.rs | 1 + crates/aiken/src/cmd/blueprint/apply.rs | 1 + crates/aiken/src/cmd/blueprint/hash.rs | 1 + crates/aiken/src/cmd/blueprint/policy.rs | 1 + crates/aiken/src/cmd/build.rs | 8 +++++--- crates/aiken/src/cmd/check.rs | 8 +++++--- crates/aiken/src/cmd/docs.rs | 8 +++++--- crates/aiken/src/main.rs | 10 ++-------- 8 files changed, 21 insertions(+), 17 deletions(-) diff --git a/crates/aiken/src/cmd/blueprint/address.rs b/crates/aiken/src/cmd/blueprint/address.rs index b90aef17..dab00111 100644 --- a/crates/aiken/src/cmd/blueprint/address.rs +++ b/crates/aiken/src/cmd/blueprint/address.rs @@ -57,4 +57,5 @@ pub fn exec( Ok(()) }) + .map_err(|_| std::process::exit(1)) } diff --git a/crates/aiken/src/cmd/blueprint/apply.rs b/crates/aiken/src/cmd/blueprint/apply.rs index b86418f5..bfde3c3a 100644 --- a/crates/aiken/src/cmd/blueprint/apply.rs +++ b/crates/aiken/src/cmd/blueprint/apply.rs @@ -147,6 +147,7 @@ pub fn exec( Ok(()) }) + .map_err(|_| std::process::exit(1)) } fn ask_schema( diff --git a/crates/aiken/src/cmd/blueprint/hash.rs b/crates/aiken/src/cmd/blueprint/hash.rs index e4a8840b..b19a00f3 100644 --- a/crates/aiken/src/cmd/blueprint/hash.rs +++ b/crates/aiken/src/cmd/blueprint/hash.rs @@ -52,4 +52,5 @@ pub fn exec( Ok(()) }) + .map_err(|_| std::process::exit(1)) } diff --git a/crates/aiken/src/cmd/blueprint/policy.rs b/crates/aiken/src/cmd/blueprint/policy.rs index f6a90f31..4bb14f15 100644 --- a/crates/aiken/src/cmd/blueprint/policy.rs +++ b/crates/aiken/src/cmd/blueprint/policy.rs @@ -52,4 +52,5 @@ pub fn exec( Ok(()) }) + .map_err(|_| std::process::exit(1)) } diff --git a/crates/aiken/src/cmd/build.rs b/crates/aiken/src/cmd/build.rs index 4067ab9e..40eb3fe0 100644 --- a/crates/aiken/src/cmd/build.rs +++ b/crates/aiken/src/cmd/build.rs @@ -1,5 +1,5 @@ use aiken_project::watch::{self, watch_project, with_project}; -use std::path::PathBuf; +use std::{path::PathBuf, process}; #[derive(clap::Args)] /// Build an Aiken project @@ -33,7 +33,7 @@ pub fn exec( keep_traces, }: Args, ) -> miette::Result<()> { - if watch { + let result = if watch { watch_project(directory.as_deref(), watch::default_filter, 500, |p| { p.build(uplc, keep_traces.into()) }) @@ -41,5 +41,7 @@ pub fn exec( with_project(directory.as_deref(), deny, |p| { p.build(uplc, keep_traces.into()) }) - } + }; + + result.map_err(|_| process::exit(1)) } diff --git a/crates/aiken/src/cmd/check.rs b/crates/aiken/src/cmd/check.rs index 63fc4068..ba05299c 100644 --- a/crates/aiken/src/cmd/check.rs +++ b/crates/aiken/src/cmd/check.rs @@ -1,5 +1,5 @@ use aiken_project::watch::{self, watch_project, with_project}; -use std::path::PathBuf; +use std::{path::PathBuf, process}; #[derive(clap::Args)] /// Type-check an Aiken project @@ -52,7 +52,7 @@ pub fn exec( .. }: Args, ) -> miette::Result<()> { - if watch { + let result = if watch { watch_project(directory.as_deref(), watch::default_filter, 500, |p| { p.check( skip_tests, @@ -72,5 +72,7 @@ pub fn exec( (!no_traces).into(), ) }) - } + }; + + result.map_err(|_| process::exit(1)) } diff --git a/crates/aiken/src/cmd/docs.rs b/crates/aiken/src/cmd/docs.rs index 2bf0be39..1abc27db 100644 --- a/crates/aiken/src/cmd/docs.rs +++ b/crates/aiken/src/cmd/docs.rs @@ -1,5 +1,5 @@ use aiken_project::watch::{self, watch_project, with_project}; -use std::path::PathBuf; +use std::{path::PathBuf, process}; #[derive(clap::Args)] /// Build the documentation for an Aiken project @@ -28,11 +28,13 @@ pub fn exec( destination, }: Args, ) -> miette::Result<()> { - if watch { + let result = if watch { watch_project(directory.as_deref(), watch::default_filter, 500, |p| { p.docs(destination.clone()) }) } else { with_project(directory.as_deref(), deny, |p| p.docs(destination.clone())) - } + }; + + result.map_err(|_| process::exit(1)) } diff --git a/crates/aiken/src/main.rs b/crates/aiken/src/main.rs index e57d03a2..ebbd5d12 100644 --- a/crates/aiken/src/main.rs +++ b/crates/aiken/src/main.rs @@ -6,14 +6,13 @@ use cmd::{ tx, uplc, Cmd, }; use owo_colors::OwoColorize; -use std::process; mod cmd; -fn main() { +fn main() -> miette::Result<()> { panic_handler(); - let result = match Cmd::default() { + match Cmd::default() { Cmd::New(args) => new::exec(args), Cmd::Fmt(args) => fmt::exec(args), Cmd::Build(args) => build::exec(args), @@ -27,11 +26,6 @@ fn main() { Cmd::Tx(sub_cmd) => tx::exec(sub_cmd), Cmd::Uplc(sub_cmd) => uplc::exec(sub_cmd), Cmd::Completion(sub_cmd) => completion::exec(sub_cmd), - }; - - match result { - Ok(()) => (), - Err(_) => process::exit(1), } }