25

When I run a binary using cargo, I have the option to run it as follows -

bash -c "RUST_BACKTRACE=1 cargo run --bin my_binary"

This gives me a stack trace when the binary hits an error. But when I create a Debian package for the same binary, how do I get stack traces on failure?

Is there some way to enable backtrace there too, if the source is implemented in Rust?

Edit:

I create a debian package for my cargo project using

cargo deb // Produces a my_binary.deb

This my_binary.deb can then be installed on a Debian machine as -

 dpkg -i /tmp/my_binary*.deb || true \
 && apt-get -f -y install
starblue
  • 55,348
  • 14
  • 97
  • 151
Rajeev Ranjan
  • 3,588
  • 6
  • 28
  • 52
  • 3
    `RUST_BACKTRACE=1 cargo run --bin my_binary` in a normal shell works for me under Debian. (Your question is somewhat unclear, what do you mean by "create a debian"?) – starblue Jan 05 '19 at 18:58
  • @starblue creating a debian was indicating creating a debian package for `my_binary`. Have edited the question. Hope it better explains now. – Rajeev Ranjan Jan 05 '19 at 19:31
  • 6
    Have you tried `RUST_BACKTRACE=1 my_binary`? – starblue Jan 05 '19 at 19:46
  • Thanks @starblue. It is a valid syntax to pass the flag like that while executing. Will see if the stacktrace gets printed on hitting an error. – Rajeev Ranjan Jan 06 '19 at 04:16

2 Answers2

26

Just in case someone is looking for setting environment variable from source code, here is how you do it:

use std::env;
fn main() {
  // this method needs to be inside main() method
  env::set_var("RUST_BACKTRACE", "1");
}

The benefit of this approach -- in contrast to manually setting the env variable from PowerShell-- is that you won't need to turn this variable off after you run this program. That is to say, 'RUST_BACKTRACE=1' is set only for this program, not others.

7

I had the same issue (error message) on Linux Mint 19 after installation of alacritty (0.5.0-dev).

In terminal just run:

RUST_BACKTRACE=1 alacritty 

or RUST_BACKTRACE=full for a verbose backtrace.

RUST_BACKTRACE=full alacritty 
Dreamer
  • 1,139
  • 9
  • 18
Alex Kulinkovich
  • 4,408
  • 15
  • 46
  • 50