From b9878afa47abd5c6a227cea34ab2ccd2830c45a9 Mon Sep 17 00:00:00 2001 From: Aleksei Fedotov <102949797+alekseifedotov@users.noreply.github.com> Date: Tue, 1 Oct 2024 20:52:38 +0200 Subject: [PATCH] fix: nicer error message when mandatory args are missing. (#247) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When running `orb-hil flash` error message looks scary: before: ``` Error: 0: you must provide either rts-path or s3-url Location: hil/src/commands/flash.rs:71 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BACKTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ⋮ 6 frames hidden ⋮ 7: orb_hil::commands::flash::Flash::run::{{closure}}::h47c7fdaa37681ba9 at /var/home/user/s/orb/software/hil/src/commands/flash.rs:71 8: orb_hil::main::{{closure}}::{{closure}}::h36e7f8c1fcea41b4 at /var/home/user/s/orb/software/hil/src/main.rs:61 9: orb_hil::main::{{closure}}::{{closure}}::h7efb28c6afe652a3 at /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/macros/select.rs:557 10: as core::future::future::Future>::poll::h2eac7c48b400a86c at /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/future/poll_fn.rs:58 11: orb_hil::main::{{closure}}::hd080318d4af69ecf at /var/home/user/s/orb/software/hil/src/main.rs:67 12: as core::future::future::Future>::poll::h3deb3e24bf77cdb1 at /builddir/build/BUILD/rust-1.81.0-build/rustc-1.81.0-src/library/core/src/future/future.rs:123 13: tokio::runtime::park::CachedParkThread::block_on::{{closure}}::h9987587e480f34d7 at /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/park.rs:281 14: tokio::runtime::coop::with_budget::h54b07592779aa816 at /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/coop.rs:107 15: tokio::runtime::coop::budget::h05bbc6d89074cce0 at /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/coop.rs:73 16: tokio::runtime::park::CachedParkThread::block_on::h7a58e96f17efc25c at /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/park.rs:281 17: tokio::runtime::context::blocking::BlockingRegionGuard::block_on::hc7718b5beb89be53 at /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/context/blocking.rs:66 18: tokio::runtime::scheduler::multi_thread::MultiThread::block_on::{{closure}}::h42267b2512734279 at /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/scheduler/multi_thread/mod.rs:87 19: tokio::runtime::context::runtime::enter_runtime::h9b729c0594cd6e2f at /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/context/runtime.rs:65 20: tokio::runtime::scheduler::multi_thread::MultiThread::block_on::he4525a3aefaaac61 at /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/scheduler/multi_thread/mod.rs:86 21: tokio::runtime::runtime::Runtime::block_on_inner::h2ee3261bdef73ded at /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/runtime.rs:363 22: tokio::runtime::runtime::Runtime::block_on::h896961fccd2a6044 at /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/runtime/runtime.rs:333 23: orb_hil::main::h23b26eec6c27f850 at /var/home/user/s/orb/software/hil/src/main.rs:67 24: core::ops::function::FnOnce::call_once::hf4ac9d2d18d88439 at /builddir/build/BUILD/rust-1.81.0-build/rustc-1.81.0-src/library/core/src/ops/function.rs:250 25: std::sys::backtrace::__rust_begin_short_backtrace::hfd91b22746c72256 at /builddir/build/BUILD/rust-1.81.0-build/rustc-1.81.0-src/library/std/src/sys/backtrace.rs:152 ⋮ 15 frames hidden ⋮ Run with COLORBT_SHOW_HIDDEN=1 environment variable to disable frame filtering. Run with RUST_BACKTRACE=full to include source snippets. ``` after: ``` error: the following required arguments were not provided: --s3-url --rts-path Usage: orb-hil flash --s3-url --rts-path For more information, try '--help'. ``` --- hil/src/commands/flash.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/hil/src/commands/flash.rs b/hil/src/commands/flash.rs index 8cb35497..c82f939e 100644 --- a/hil/src/commands/flash.rs +++ b/hil/src/commands/flash.rs @@ -11,13 +11,17 @@ use crate::{current_dir, download_s3::ExistingFileBehavior, flash::FlashVariant} #[derive(Parser, Debug)] pub struct Flash { /// The s3 URI of the rts. - #[arg(long)] + #[arg( + long, + conflicts_with = "rts_path", + required_unless_present = "rts_path" + )] s3_url: Option, /// The directory to save the s3 artifact we download. #[arg(long)] download_dir: Option, /// Skips download by using an existing tarball on the filesystem. - #[arg(long)] + #[arg(long, conflicts_with = "s3_url", required_unless_present = "s3_url")] rts_path: Option, /// If this flag is given, uses flashcmd.txt instead of fastflashcmd.txt #[arg(long)]