Skip to content

Commit

Permalink
Add custom error message for use of --native on unsupported platfor…
Browse files Browse the repository at this point in the history
…ms (#700)
  • Loading branch information
zanieb authored Oct 15, 2024
1 parent f01b43a commit 94fb024
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,16 @@ impl Config {
.help("PID of a running python program to spy on")
.takes_value(true);

#[cfg(feature = "unwind")]
let native = Arg::new("native")
let mut native = Arg::new("native")
.short('n')
.long("native")
.help("Collect stack traces from native extensions written in Cython, C or C++");

// Only show `--native` on platforms where it's supported
if !cfg!(feature = "unwind") {
native = native.hide(true);
}

#[cfg(not(target_os="freebsd"))]
let nonblocking = Arg::new("nonblocking")
.long("nonblocking")
Expand Down Expand Up @@ -327,12 +331,8 @@ impl Config {
.help("Shell type"),
);

// add native unwinding if appropriate
#[cfg(feature = "unwind")]
let record = record.arg(native.clone());
#[cfg(feature = "unwind")]
let top = top.arg(native.clone());
#[cfg(feature = "unwind")]
let dump = dump.arg(native.clone());

// Nonblocking isn't an option for freebsd, remove
Expand Down Expand Up @@ -361,6 +361,14 @@ impl Config {

let (subcommand, matches) = matches.subcommand().unwrap();

// Check if `--native` was used on an unsupported platform
if !cfg!(feature = "unwind") && matches.contains_id("native") {
eprintln!(
"Collecting stack traces from native extensions (`--native`) is not supported on your platform."
);
std::process::exit(1);
}

match subcommand {
"record" => {
config.sampling_rate = matches.value_of_t("rate")?;
Expand Down

0 comments on commit 94fb024

Please sign in to comment.