Skip to content

File Not Found : Meaningful error messages to identify exact issue #44938

@dumindu

Description

@dumindu

Folder structure

├── Cargo.toml
└── src
   ├── hello.txt
   └── main.rs

main.rs

use std::fs::File;

fn main() {
    let _file = File::open("hello.txt").expect("file not found");
    println!("{}", "Hello World!");
}

Error

Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
Running `target/debug/read_file`

thread 'main' panicked at 'file not found: Error { repr: Os { code: 2, message: "No such file or directory" } }', src/libcore/result.rs:906:4
stack backtrace:
   0:        0x10c4135f3 - std::sys::imp::backtrace::tracing::imp::unwind_backtrace::h3160619f5df0b429
   1:        0x10c40fe30 - std::sys_common::backtrace::_print::h1120036038320f80
   2:        0x10c4149e3 - std::panicking::default_hook::{{closure}}::hb299632e05329bb5
   3:        0x10c4146e2 - std::panicking::default_hook::h00107bf0a85963b4
   4:        0x10c414e32 - std::panicking::rust_panic_with_hook::hd9c6ad24a775c34c
   5:        0x10c414d14 - std::panicking::begin_panic::h49e0d0a8e06c5478
   6:        0x10c414be2 - std::panicking::begin_panic_fmt::h1694ee0907f92803
   7:        0x10c414b4a - rust_begin_unwind
   8:        0x10c4462c3 - core::panicking::panic_fmt::h2d82c8387bfa11ba
   9:        0x10c407c4c - core::result::unwrap_failed::he129861d908021e0
  10:        0x10c407f28 - <core::result::Result<T, E>>::expect::h1db24ec21ca210c8
  11:        0x10c40841e - read_file::main::hfb1b70fb4d7706fb
  12:        0x10c444edc - __rust_maybe_catch_panic
  13:        0x10c415128 - std::rt::lang_start::h3fa27024f6a74294
  14:        0x10c408509 - main

Process finished with exit code 101

Expected error message

No such file in <absolute path>

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions