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

refactor: add automatic conversion for nix::Errno #4060

Merged
merged 10 commits into from
Nov 4, 2022

Conversation

orhun
Copy link
Contributor

@orhun orhun commented Oct 18, 2022

An attempt to fix #4007

@sylvestre
Copy link
Contributor

it would be nice to test this :)
thanks

@@ -508,6 +508,17 @@ impl From<std::io::Error> for Box<dyn UError> {
}
}

impl<T> FromIo<UResult<T>> for Result<T, nix::Error> {
Copy link
Contributor

Choose a reason for hiding this comment

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

needs some comments here :)
and usage examples

Copy link
Contributor

Choose a reason for hiding this comment

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

see the function below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@github-actions
Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/misc/tee is no longer failing!
GNU test failed: tests/misc/sync. tests/misc/sync is passing on 'main'. Maybe you have to rebase?
GNU test failed: tests/rm/rm2. tests/rm/rm2 is passing on 'main'. Maybe you have to rebase?

@tertsdiepraam
Copy link
Member

Cool! This is exactly what I had in mind. I'd just like to have it implemented for nix::error (without being wrapped in a result) as well. (And I agree with Sylvestre's comments)

@orhun
Copy link
Contributor Author

orhun commented Oct 20, 2022

it would be nice to test this :)

How can I test it? Is adding usage examples as comments enough?

I'd just like to have it implemented for nix::error (without being wrapped in a result) as well.

Do you mean impl<T> FromIo<UResult<T>> for nix::Error or impl FromIo<UIoError> for nix::Error? Both are possible and I don't know which one is more convenient.

@tertsdiepraam
Copy link
Member

How can I test it? Is adding usage examples as comments enough?

You could make a unit test that you know gives an error and assert that the error that you get is correct.

Do you mean impl<T> FromIo<UResult<T>> for nix::Error or impl FromIo<UIoError> for nix::Error? Both are possible and I don't know which one is more convenient.

The same as for std::io::Error. We map to Box<UIoError> because that's what goes into a UResult:

impl FromIo<Box<UIoError>> for std::io::Error {
    fn map_err_context(self, context: impl FnOnce() -> String) -> Box<UIoError> {
        Box::new(UIoError {
            context: Some((context)()),
            inner: self,
        })
    }
}
impl<T> FromIo<UResult<T>> for std::io::Result<T> {
    fn map_err_context(self, context: impl FnOnce() -> String) -> UResult<T> {
        self.map_err(|e| e.map_err_context(context) as Box<dyn UError>)
    }
}

These would also be nice to have for nix::error:

impl From<std::io::Error> for UIoError {
    fn from(f: std::io::Error) -> Self {
        Self {
            context: None,
            inner: f,
        }
    }
}
impl From<std::io::Error> for Box<dyn UError> {
    fn from(f: std::io::Error) -> Self {
        let u_error: UIoError = f.into();
        Box::new(u_error) as Self
    }
}

@sylvestre
Copy link
Contributor

Could you please fix the clippy warning? thanks

@github-actions
Copy link

GNU testsuite comparison:

GNU test failed: tests/misc/sync. tests/misc/sync is passing on 'main'. Maybe you have to rebase?

@orhun orhun requested a review from sylvestre October 22, 2022 18:37
@github-actions
Copy link

GNU testsuite comparison:

GNU test failed: tests/misc/sync. tests/misc/sync is passing on 'main'. Maybe you have to rebase?
GNU test failed: tests/misc/tee. tests/misc/tee is passing on 'main'. Maybe you have to rebase?

@orhun
Copy link
Contributor Author

orhun commented Oct 23, 2022

I'm not sure why the CI is failing.

@orhun
Copy link
Contributor Author

orhun commented Oct 30, 2022

Friendly ping 🏓

@sylvestre
Copy link
Contributor

Just rebased it. It had some job failures

@github-actions
Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/misc/timeout is no longer failing!
GNU test failed: tests/misc/sync. tests/misc/sync is passing on 'main'. Maybe you have to rebase?

@sylvestre
Copy link
Contributor

Could you please have a look to https://github.com/uutils/coreutils/actions/runs/3355920132/jobs/5560563514?

@sylvestre
Copy link
Contributor

ping? :)

@github-actions
Copy link

github-actions bot commented Nov 4, 2022

GNU testsuite comparison:

GNU test failed: tests/misc/sync. tests/misc/sync is passing on 'main'. Maybe you have to rebase?

1 similar comment
@github-actions
Copy link

github-actions bot commented Nov 4, 2022

GNU testsuite comparison:

GNU test failed: tests/misc/sync. tests/misc/sync is passing on 'main'. Maybe you have to rebase?

@orhun
Copy link
Contributor Author

orhun commented Nov 4, 2022

Still not sure why the CI is failing 🤔

@sylvestre
Copy link
Contributor

you can ignore these :)

@sylvestre sylvestre merged commit f32f89c into uutils:main Nov 4, 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.

Add automatic conversion from nix::Errno to UError like we have for std::io::Error.
3 participants