Skip to content

Allow renaming RUST_BACKTRACE to MYCRATE_BACKTRACE #2599

@nvzqz

Description

@nvzqz
Contributor

It would be nice if we could rename the RUST_BACKTRACE environment variable to something custom like MYCRATE_BACKTRACE. This idea came to me from looking at env_logger and how you can rename the environment variable it uses via from_env.

I suggest something along the lines of this:

#![backtrace_env = "MYCRATE_BACKTRACE"]

fn main() {
    // ...
}

And then enabling it via:

MYCRATE_BACKTRACE=1 ./mycrate

Supporting reasons:

  • Gives some sense of consistency for end users who may not know what Rust is, where the current variable name may be confusing
  • Some authors believe the end user has no business knowing what language their program was written in
  • Backtraces may be enabled for some Rust programs but not all when executed in the same environment, such as in a shell script

Activity

added
T-langRelevant to the language team, which will review and decide on the RFC.
T-compilerRelevant to the compiler team, which will review and decide on the RFC.
A-debuggingDebugging related proposals & ideas
A-envEnvironment variable related proposals & ideas
A-attributesProposals relating to attributes
on Nov 24, 2018
SimonSapin

SimonSapin commented on Nov 24, 2018

@SimonSapin
Contributor

If your crate is an executable, it could use std::env::set_var near the start of main to set RUST_BACKTRACE based on some other env variable.

nvzqz

nvzqz commented on Nov 24, 2018

@nvzqz
ContributorAuthor

Right, but that doesn't change panics from spitting out the following:

thread 'main' panicked at ...
note: Run with `RUST_BACKTRACE=1` for a backtrace

I would like for it to suggest running MYCRATE_BACKTRACE=1 instead. I know I can just catch panics in main and output my own message but it'd be nice to have that without so much boilerplate.

sfackler

sfackler commented on Nov 25, 2018

@sfackler
Member

You can use std::panic::set_hook to run whatever custom logic you want on panic.

mqudsi

mqudsi commented on Dec 23, 2018

@mqudsi

Gives some sense of consistency for end users who may not know what Rust is, where the current variable name may be confusing

At the cost of taking consistency away from the rust ecosystem as a whole. I don't need to double-check that I've got the (difficult to read since it's all-caps) environment variable name correct each time I cargo run a project to see what the author decided to call their backtrace variable. Within the rust ecosystem, it's always env RUST_BACKTRACE=1 cargo run, end of story.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-attributesProposals relating to attributesA-debuggingDebugging related proposals & ideasA-envEnvironment variable related proposals & ideasT-compilerRelevant to the compiler team, which will review and decide on the RFC.T-langRelevant to the language team, which will review and decide on the RFC.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @SimonSapin@mqudsi@Centril@sfackler@nvzqz

        Issue actions

          Allow renaming RUST_BACKTRACE to MYCRATE_BACKTRACE · Issue #2599 · rust-lang/rfcs