Need help seeing rust error traceback

How do i run a rust repl with RUST_BACKTRACE=1?

my rust program is panicking at an index out of bounds error, and I would like to see the backtrace for this, but I dont know how.

error:

thread 'main' panicked at 'index out of bounds: the len is 19 but the index is 19', src/parser.rs:65:15
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
exit status 101

so how do I run with RUST_BACKTRACE=1?

Try editing .replit to include this information somewhere. If you can’t see it, click the three dots and “Show Hidden Files” in the Replit file browser.

I dont see anything involving environment variables in the .replit file, i tried running the program using cargo run RUST_BACKTRACE=1 but it didnt change anything

I don’t know, but maybe setting a secret called “RUST_BACKTRACE” with a value of 1 would work? Those are environment variables.

3 Likes

Oh that did the trick, Thanks!

2 Likes

:confetti_ball: to make it work on forks of your repl, and make it clear that the env is being set, you could instead add it to the env section of the .replit file

[env]
RUST_BACKTRACE = "1"
3 Likes

i get this error when i add that to the .replit file

unable to read .replit:
unable to decode .replit: toml: line 30 (last key "env.RUST_BACKTRACE"): incompatible types: TOML value has type int64; destination has type string
nix error: building nix env: problem reading '.replit' file: unable to decode .replit: toml: line 30 (last key "env.RUST_BACKTRACE"): incompatible types: TOML value has type int64; destination has type string
1 Like

yeah, I had hit Reply too quickly. The 1 is meant to be quoted

4 Likes

oh yes that fixed it, thanks

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.