0

I have a rust program that panicked with the message

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ParseFloatError { kind: Invalid }', src/functions.rs.inc:58:42
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

I searched hard, but I cannot find any hints how to set the desired environment variable in cargo or rust. I found on my Linux machine /home/pi/.cargo/env and added RUST_BACKTRACE=1 in that file, but it does not makes a difference.

How do I set RUST_BACKTRACE=1 to find the reason for suddenly occurring panics?

Brian61354270
  • 8,690
  • 4
  • 21
  • 43
hig
  • 17
  • 1
  • 4
    How are you invoking cargo? If you're invoking it directly from a shell, you can just write `RUST_BACKTRACE=1 cargo `. If you're using it through an IDE run configuration, there should be an option in the run configuration settings to set environment variables. – Brian61354270 Jun 10 '21 at 15:18
  • I edited-out the code in your question that was causing the panic since it isn't strictly relevant to your actual question of how to set an environment variable. – Brian61354270 Jun 10 '21 at 15:30
  • ... I _flagged_ this question, why'd that get converted into a silly little comment!? – mmirate Jun 11 '21 at 13:01
  • 1
    @mmirate You flagged as duplicate (thanks for that contribution). It seems that your proposal was confirmed by two users with the corresponding close-vote privilege. When you flag (or they close-vote) a comment is created, that is what you see. It's a feature, not a bug. One more of that and the question will be closed. – Yunnosch Jun 11 '21 at 13:07
  • Thanks for the answers. I tried 'export RUST_BACKTRACE=1', it was accepted but it didn't have any effect in giving more information. I have to start my application with 'sudo target/debug/logger' because it uses the GPIO of Raspi3B, so I can't use cargo to let it run. Bash accepts also 'RUST_BACKTRACE=1 sudo target/debug/logger', but with that call up to now the error/panick didn't show up any more. – hig Jun 11 '21 at 16:39
  • For security reasons, sudo doesn't always pass environment variables through. You should try to rule out such an occurrence. – mmirate Jul 18 '21 at 15:13

0 Answers0