# The API of \`Path::exists()\` encourages broken code

**URL:** <https://internals.rust-lang.org/t/the-api-of-path-exists-encourages-broken-code/13817>\
**Category:** Uncategorized\
**Created:** [January 12, 2021, 12:16pm UTC](https://internals.rust-lang.org/t/the-api-of-path-exists-encourages-broken-code/13817 "2021-01-12T12:16:06Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![Kixunil](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/kixunil/32/4110_2.png) [@Kixunil](https://internals.rust-lang.org/u/Kixunil)\
**Post date:** [January 12, 2021, 12:16pm UTC](https://internals.rust-lang.org/t/the-api-of-path-exists-encourages-broken-code/13817/1 "2021-01-12T12:16:06Z")

</div>

Consider a situation in which a user wants to check existence of a file. However, the user doesn't have access to the directory that would contain the file. As a result, permission denied error happens internally but gets silently converted to `false`.

I don't believe that "false" is the right answer to "does this file exist?" if a program is not allowed to know.

I suggest to replace `exists` with `try_exists`, which returns `io::Result<bool>` and deprecate `exists`. I suspect an RFC is needed for this, right?

I guess that some people might have meant `accessible` when writing `exists`, so perhaps add `accessible` method that internally calls `access` on Unixes (IDK if there's something similar on Windows). However there's an interesting difference between UID and EUID, which should be documented.

Other discussion in [Add `fs::exists` function by hamza1311 · Pull Request #3375 · tokio-rs/tokio · GitHub](https://github.com/tokio-rs/tokio/pull/3375)

---

_[View the full topic](https://internals.rust-lang.org/t/the-api-of-path-exists-encourages-broken-code/13817)._
