Skip to content

Commit

Permalink
fix: nicer error message when mandatory args are missing. (#247)
Browse files Browse the repository at this point in the history
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: <tokio::future::poll_fn::PollFn<F> 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: <core::pin::Pin<P> 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 <S3_URL>
  --rts-path <RTS_PATH>

Usage: orb-hil flash --s3-url <S3_URL> --rts-path <RTS_PATH>

For more information, try '--help'.
```
  • Loading branch information
alekseifedotov authored Oct 1, 2024
1 parent 3e258f7 commit b9878af
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions hil/src/commands/flash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
/// The directory to save the s3 artifact we download.
#[arg(long)]
download_dir: Option<Utf8PathBuf>,
/// 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<Utf8PathBuf>,
/// If this flag is given, uses flashcmd.txt instead of fastflashcmd.txt
#[arg(long)]
Expand Down

0 comments on commit b9878af

Please sign in to comment.