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

Report io error when detect cannot read a file. #243

Merged
merged 2 commits into from
Jan 15, 2024

Conversation

schneems
Copy link
Contributor

It's best practice to use try_exists() instead of exists() when checking if a file exists or not because if there's a problem with the file (such as a permissions issue) then the check might fail even though the file is on disk. This seems like not a big deal, but can be very confusing when telling users "we didn't do X because you are missing file Y" but when they debug they see file Y and don't realize that the real problem isn't "missing file" but it's the hidden error preventing exists() from returning a true.

This commit uses fs_err_try_exists() from fs-err library that was introduced in: andrewhickman/fs-err#48.

There are a few other places where exists is still called, those are nested in areas that don't already return a Result so they're harder to swap.

@schneems schneems marked this pull request as ready for review November 29, 2023 17:51
@schneems schneems requested a review from a team as a code owner November 29, 2023 17:51
It's best practice to use `try_exists()` instead of `exists()` when checking if a file exists or not because if there's a problem with the file (such as a permissions issue) then the check might fail even though the file is on disk. This seems like not a big deal, but can be very confusing when telling users "we didn't do X because you are missing file Y" but when they debug they see file Y and don't realize that the real problem isn't "missing file" but it's the hidden error preventing `exists()` from returning a true.


This commit uses fs_err_try_exists() from fs-err library that was introduced in: andrewhickman/fs-err#48.

There are a few other places where `exists` is still called, those are nested in areas that don't already return a Result so they're harder to swap.
@schneems schneems enabled auto-merge (squash) November 29, 2023 22:55
buildpacks/ruby/src/user_errors.rs Outdated Show resolved Hide resolved
buildpacks/ruby/src/user_errors.rs Outdated Show resolved Hide resolved
buildpacks/ruby/src/user_errors.rs Outdated Show resolved Hide resolved
buildpacks/ruby/src/user_errors.rs Outdated Show resolved Hide resolved
buildpacks/ruby/src/user_errors.rs Outdated Show resolved Hide resolved
buildpacks/ruby/src/user_errors.rs Outdated Show resolved Hide resolved
buildpacks/ruby/src/user_errors.rs Outdated Show resolved Hide resolved
buildpacks/ruby/src/user_errors.rs Outdated Show resolved Hide resolved
Explanation from colin:

If you kept the text as it, it could break too early and leave a lot of whitespace:

```
The Ruby buildpack detected a package.json file but it is not readable           | <- term width
due to the following errors:                                                     |
```

This is sometimes okay.  or the worse case is a small terminal where it breaks too late and causes weird wrapping:

```
The Ruby buildpack detected a package.json file but | <- term width 
it is not readable                                  |
due to the following errors:                        |
```
---
Richard: I agree this is a sub-optimal experience. We should use double newline to indicate paragraphs and let the terminal handle wrapping for us within the paragraph.

I'm unsure of how this will interact with colorized output as it might color the `remoteL` annotations. Either that or the indentation won't align. I'm not sure how different terminals handle that case. 

Trying it out it looks like this:

```
$ cat bin/detect
#!/usr/bin/env bash

echo "Worked"
⛄️ 3.1.4 🚀 /tmp/8efcb3e683a408206c4c8f017697f813 (main)
$ cat bin/compile
#!/usr/bin/env bash

echo -e "\e[0;31mhihihihihihihihihihi hihihihihihihihihihihihihihihi hihihihihihihi hi hihihihihihihihihi hihihihihihihihihihi hihihihihihi hihihihihihihihihihi hihihihihihihihihi hihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihi hihihi\e[0m"
⛄️ 3.1.4 🚀 /tmp/8efcb3e683a408206c4c8f017697f813 (main)
$ heroku buildpacks
=== immense-beyond-95949 Buildpack URL

heroku-community/inline
```

```
$ git push
Enumerating objects: 7, done.
Counting objects: 100% (7/7), done.
Delta compression using up to 12 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (7/7), 482 bytes | 482.00 KiB/s, done.
Total 7 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Updated 3 paths from e061d88
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-22 stack
remote: -----> Using buildpack: heroku-community/inline
remote: -----> Worked app detected
remote: hihihihihihihihihihi hihihihihihihihihihihihihihihi hihihihihihihi hi hihihihihihihihihi hihihihihihihihihihi hihihihihihi hihihihihihihihihihi hihihihihihihihihi hihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihi hihihi
remote: -----> Discovering process types
remote:        Procfile declares types -> (none)
remote:
remote: -----> Compressing...
remote:        Done: 320B
remote: -----> Launching...
remote:        Released v3
remote:        https://immense-beyond-95949-a2b498662b8a.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/immense-beyond-95949.git
 * [new branch]      main -> main
```

It looks like this: https://imgur.com/a/sOscF4m

Co-authored-by: Colin Casey <casey.colin@gmail.com>
@schneems schneems merged commit add3ee7 into main Jan 15, 2024
6 checks passed
@schneems schneems deleted the schneems/fs_err_try_exists branch January 15, 2024 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants