This is a reference to help answer this question: โ€œwhat will my Rust program print if something goes wrong?โ€

The examples were compiled with Rust 1.76.0. All output in these examples goes to stderr, nothing goes to stdout.

Setup code for stable_eyre

fn make_error() -> Result<(), stable_eyre::eyre::Report> {
    Ok(std::fs::remove_file("/this/file/does/not/exist")?)
}

fn install_hook() -> stable_eyre::eyre::Result<()> {
    let hook =
        stable_eyre::HookBuilder::default().capture_backtrace_by_default(true);
    hook.install()
}

Debug

fn main() {
    install_hook().unwrap();
    eprintln!("{:?}", make_error().unwrap_err())
}
No such file or directory (os error 2)

Stack backtrace:
   0: stable_eyre::HookBuilder::make_handler
             at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/stable-eyre-0.2.2/src/lib.rs:145:18
   1: stable_eyre::HookBuilder::install::{{closure}}
             at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/stable-eyre-0.2.2/src/lib.rs:168:58
   2: eyre::capture_handler
             at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/eyre-0.6.12/src/lib.rs:601:23
   3: eyre::error::::from_std
             at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/eyre-0.6.12/src/error.rs:90:28
   4: eyre::error:: for eyre::Report>::from
             at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/eyre-0.6.12/src/error.rs:496:9
   5:  as core::ops::try_trait::FromResidual>>::from_residual
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/result.rs:1959:27
   6: stable_eyre_debug::make_error
             at /home/runner/work/rust-error-output/rust-error-output/gen/src/bin/stable_eyre_debug.rs:2:8
   7: stable_eyre_debug::main
             at /home/runner/work/rust-error-output/rust-error-output/gen/src/bin/stable_eyre_debug.rs:12:23
   8: core::ops::function::FnOnce::call_once
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/ops/function.rs:250:5
   9: std::sys_common::backtrace::__rust_begin_short_backtrace
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/sys_common/backtrace.rs:155:18
  10: std::rt::lang_start::{{closure}}
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/rt.rs:166:18
  11: core::ops::function::impls:: for &F>::call_once
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/ops/function.rs:284:13
      std::panicking::try::do_call
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:552:40
      std::panicking::try
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:516:19
      std::panic::catch_unwind
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panic.rs:142:14
      std::rt::lang_start_internal::{{closure}}
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/rt.rs:148:48
      std::panicking::try::do_call
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:552:40
      std::panicking::try
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:516:19
      std::panic::catch_unwind
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panic.rs:142:14
      std::rt::lang_start_internal
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/rt.rs:148:20
  12: std::rt::lang_start
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/rt.rs:165:17
  13: main
  14: 
  15: __libc_start_main
  16: _start

Display

fn main() {
    install_hook().unwrap();
    eprintln!("{}", make_error().unwrap_err())
}
No such file or directory (os error 2)

Alternate Display

fn main() {
    install_hook().unwrap();
    eprintln!("{:#}", make_error().unwrap_err())
}
No such file or directory (os error 2)

Unwrap

fn main() {
    install_hook().unwrap();
    make_error().unwrap();
}
thread 'main' panicked at src/bin/stable_eyre_unwrap.rs:12:18:
called `Result::unwrap()` on an `Err` value: No such file or directory (os error 2)

Stack backtrace:
   0: stable_eyre::HookBuilder::make_handler
             at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/stable-eyre-0.2.2/src/lib.rs:145:18
   1: stable_eyre::HookBuilder::install::{{closure}}
             at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/stable-eyre-0.2.2/src/lib.rs:168:58
   2: eyre::capture_handler
             at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/eyre-0.6.12/src/lib.rs:601:23
   3: eyre::error::::from_std
             at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/eyre-0.6.12/src/error.rs:90:28
   4: eyre::error:: for eyre::Report>::from
             at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/eyre-0.6.12/src/error.rs:496:9
   5:  as core::ops::try_trait::FromResidual>>::from_residual
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/result.rs:1959:27
   6: stable_eyre_unwrap::make_error
             at /home/runner/work/rust-error-output/rust-error-output/gen/src/bin/stable_eyre_unwrap.rs:2:8
   7: stable_eyre_unwrap::main
             at /home/runner/work/rust-error-output/rust-error-output/gen/src/bin/stable_eyre_unwrap.rs:12:5
   8: core::ops::function::FnOnce::call_once
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/ops/function.rs:250:5
   9: std::sys_common::backtrace::__rust_begin_short_backtrace
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/sys_common/backtrace.rs:155:18
  10: std::rt::lang_start::{{closure}}
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/rt.rs:166:18
  11: core::ops::function::impls:: for &F>::call_once
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/ops/function.rs:284:13
      std::panicking::try::do_call
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:552:40
      std::panicking::try
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:516:19
      std::panic::catch_unwind
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panic.rs:142:14
      std::rt::lang_start_internal::{{closure}}
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/rt.rs:148:48
      std::panicking::try::do_call
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:552:40
      std::panicking::try
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:516:19
      std::panic::catch_unwind
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panic.rs:142:14
      std::rt::lang_start_internal
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/rt.rs:148:20
  12: std::rt::lang_start
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/rt.rs:165:17
  13: main
  14: 
  15: __libc_start_main
  16: _start

note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Expect

fn main() {
    install_hook().unwrap();
    make_error().expect("oh no");
}
thread 'main' panicked at src/bin/stable_eyre_expect.rs:12:18:
oh no: No such file or directory (os error 2)

Stack backtrace:
   0: stable_eyre::HookBuilder::make_handler
             at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/stable-eyre-0.2.2/src/lib.rs:145:18
   1: stable_eyre::HookBuilder::install::{{closure}}
             at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/stable-eyre-0.2.2/src/lib.rs:168:58
   2: eyre::capture_handler
             at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/eyre-0.6.12/src/lib.rs:601:23
   3: eyre::error::::from_std
             at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/eyre-0.6.12/src/error.rs:90:28
   4: eyre::error:: for eyre::Report>::from
             at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/eyre-0.6.12/src/error.rs:496:9
   5:  as core::ops::try_trait::FromResidual>>::from_residual
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/result.rs:1959:27
   6: stable_eyre_expect::make_error
             at /home/runner/work/rust-error-output/rust-error-output/gen/src/bin/stable_eyre_expect.rs:2:8
   7: stable_eyre_expect::main
             at /home/runner/work/rust-error-output/rust-error-output/gen/src/bin/stable_eyre_expect.rs:12:5
   8: core::ops::function::FnOnce::call_once
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/ops/function.rs:250:5
   9: std::sys_common::backtrace::__rust_begin_short_backtrace
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/sys_common/backtrace.rs:155:18
  10: std::rt::lang_start::{{closure}}
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/rt.rs:166:18
  11: core::ops::function::impls:: for &F>::call_once
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/ops/function.rs:284:13
      std::panicking::try::do_call
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:552:40
      std::panicking::try
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:516:19
      std::panic::catch_unwind
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panic.rs:142:14
      std::rt::lang_start_internal::{{closure}}
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/rt.rs:148:48
      std::panicking::try::do_call
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:552:40
      std::panicking::try
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:516:19
      std::panic::catch_unwind
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panic.rs:142:14
      std::rt::lang_start_internal
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/rt.rs:148:20
  12: std::rt::lang_start
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/rt.rs:165:17
  13: main
  14: 
  15: __libc_start_main
  16: _start

note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Return

fn main() -> Result<(), stable_eyre::eyre::Report> {
    install_hook()?;
    make_error()
}
Error: No such file or directory (os error 2)

Stack backtrace:
   0: stable_eyre::HookBuilder::make_handler
             at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/stable-eyre-0.2.2/src/lib.rs:145:18
   1: stable_eyre::HookBuilder::install::{{closure}}
             at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/stable-eyre-0.2.2/src/lib.rs:168:58
   2: eyre::capture_handler
             at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/eyre-0.6.12/src/lib.rs:601:23
   3: eyre::error::::from_std
             at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/eyre-0.6.12/src/error.rs:90:28
   4: eyre::error:: for eyre::Report>::from
             at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/eyre-0.6.12/src/error.rs:496:9
   5:  as core::ops::try_trait::FromResidual>>::from_residual
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/result.rs:1959:27
   6: stable_eyre_return::make_error
             at /home/runner/work/rust-error-output/rust-error-output/gen/src/bin/stable_eyre_return.rs:2:8
   7: stable_eyre_return::main
             at /home/runner/work/rust-error-output/rust-error-output/gen/src/bin/stable_eyre_return.rs:12:5
   8: core::ops::function::FnOnce::call_once
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/ops/function.rs:250:5
   9: std::sys_common::backtrace::__rust_begin_short_backtrace
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/sys_common/backtrace.rs:155:18
  10: std::rt::lang_start::{{closure}}
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/rt.rs:166:18
  11: core::ops::function::impls:: for &F>::call_once
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/ops/function.rs:284:13
      std::panicking::try::do_call
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:552:40
      std::panicking::try
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:516:19
      std::panic::catch_unwind
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panic.rs:142:14
      std::rt::lang_start_internal::{{closure}}
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/rt.rs:148:48
      std::panicking::try::do_call
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:552:40
      std::panicking::try
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:516:19
      std::panic::catch_unwind
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panic.rs:142:14
      std::rt::lang_start_internal
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/rt.rs:148:20
  12: std::rt::lang_start
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/rt.rs:165:17
  13: main
  14: 
  15: __libc_start_main
  16: _start