Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set RUST_BACKTRACE=1 when running programs #1517

Closed
kornelski opened this Issue Apr 12, 2015 · 8 comments

Comments

Projects
None yet
3 participants
@kornelski
Copy link
Contributor

kornelski commented Apr 12, 2015

RUST_BACKTRACE=1 is super-useful, but not very discoverable. It's a trick I wish I knew earlier.

Currently rust has very unhelpful error messages in many common cases, because assertions in the stdlib point to code inside stdlib, rather than user's code that is the root cause of the problem. Backtrace output is essential to diagnose problems.

Cargo could be helpful here and set RUST_BACKTRACE=1 automatically when running examples and binaries.

If having it on all the time is a problem, then it could be disabled in --release or enabled with --verbose (which would make it more meaningful than #1516) — these flags are still more discoverable than an environmental variable.

@huonw huonw added the Command-run label Apr 12, 2015

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Apr 13, 2015

I would personally be pretty surprised by this behavior as Cargo wants to be as thin a shim as possible on top of running a program. Adding this sort of behavior would inevitable lead to the need for further configuration (such as leaving the environment variable off with --verbose).

Perhaps the discoverability problem could be solved rather than adding special logic to cargo?

@kornelski

This comment has been minimized.

Copy link
Contributor Author

kornelski commented Apr 13, 2015

What would be the recommendation for users? Have export RUST_BACKTRACE=1 always set? Are there any downsides to this?

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Apr 13, 2015

I would recommend setting it when needed, although having a global RUST_BACKTRACE=1 is also always an option!

I see this as a downside as it is affecting behavior in a way that will need further configuration to revert back to the default behavior today.

@kornelski

This comment has been minimized.

Copy link
Contributor Author

kornelski commented Apr 14, 2015

I was asking about downside of setting backtrace on, becaue if it shouldn't be set all the time, then cargo is in unique position to set it for the program being run, but not for rustc and the cargo itself.
"RUST_BACKTRACE=1 cargo run" sets it for all of them, and it's another bit of boilerplate to know and type.

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Apr 14, 2015

The downside is that if you don't want it set, Cargo needs to grow its own configuration to not pass the environment variable, which is more surface area to work through and not necessarily worth it.

@kornelski

This comment has been minimized.

Copy link
Contributor Author

kornelski commented Apr 14, 2015

Could you check for and honor RUST_BACKTRACE=0 (with 0 as opposed to unset or empty string)? Then override wouldn't be harder than usual way of setting it, but the cargo's default could still be smart.

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Apr 15, 2015

Right, but this rabbit hole keeps going because what if the integer being passed to RUST_BACKTRACE is interpreted by the standard library one day? Having Cargo do as little as possible I've found to work quite well as reducing the amount of friction between cargo run and a manual ./target/debug/foo has been very nice in the past. Adding small features like this will only increase the difference there and make it more difficult to run binaries by hand.

@kornelski

This comment has been minimized.

Copy link
Contributor Author

kornelski commented Apr 15, 2015

OK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.