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

df: better error message when executed in a chroot without /proc #3601 #3602

Merged
merged 5 commits into from
Jul 11, 2022
Merged

df: better error message when executed in a chroot without /proc #3601 #3602

merged 5 commits into from
Jul 11, 2022

Conversation

lendandgit
Copy link
Contributor

No description provided.

@sylvestre
Copy link
Contributor

Please fix the warning:


error: useless use of `format!`
   --> src/uu/df/src/df.rs:451:25
    |
451 |                         format!("cannot read table of mounted file systems"),
    |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"cannot read table of mounted file systems".to_string()`
    |
    = note: `-D clippy::useless-format` implied by `-D warnings`

@lendandgit
Copy link
Contributor Author

Thank you for pointing out the warning. I have fixed it in the new commit.

Copy link
Member

@tertsdiepraam tertsdiepraam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks! I just have one suggestion for a little bit of further cleanup.

@@ -448,7 +448,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
Err(error) => {
Copy link
Member

@tertsdiepraam tertsdiepraam Jun 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be:

use uucore::error::FromIo;
// --- snip ---
let filesystems = get_all_filesystems(&opt)
    .map_err_context(|| "cannot read table of mounted file systems".into())?;

See the docs for UIoError.

Sidenote: if you have any ideas about how to make this feature more discoverable/intuitive, I would be happy to hear it, because first-time contributors often miss this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made the requested changes in the new commit, thanks for the suggestion.

It would be useful for first-time contributors to explicitly recommend this way of error construction in the documentation.

Copy link
Member

@tertsdiepraam tertsdiepraam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Is it possible to add a test for this?

@@ -501,7 +501,7 @@ impl Stater {
// mount points aren't displayed when showing filesystem information
None
} else {
let mut mount_list = read_fs_list()
let mut mount_list = read_fs_list()?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering about this case, because it's currently missing a context. Do we know that GNU's error in this case is?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested the Rust and GNU versions of stat in the same environment I used to test df (chroot without proc).
While the Rust version fails, the GNU version does not but displays the expected output. For this reason I was not able to produce the error with GNU's stat.

I could only find GNU's error message in the sources:

https://github.com/coreutils/coreutils/blob/93e099e4c3b659b2e329f655fbdc73fdf594a66e/src/stat.c#L961

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, let's use that error message in stat then too

@lendandgit
Copy link
Contributor Author

To add a test I would need a way to make /proc inaccessible to df. Is that possible?

@tertsdiepraam
Copy link
Member

To add a test I would need a way to make /proc inaccessible to df. Is that possible?

Hmm, yeah I guess that's not really possible. At least not with how the tests are currently set up.

@lendandgit lendandgit requested a review from tertsdiepraam June 10, 2022 19:06
@sylvestre
Copy link
Contributor

@tertsdiepraam is it ok with you?

@tertsdiepraam tertsdiepraam merged commit 6b00aec into uutils:main Jul 11, 2022
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.

df: the error should be better displayed when executed in a chroot without /proc
3 participants