Skip to content

Remove crash macro from fmt and unexpand #5522

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

Closed
wants to merge 2 commits into from

Conversation

alexhausen
Copy link
Contributor

This PR is related to #5487.
It removes the crash! macro from fmt and unexpand.

Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/tail/truncate is no longer failing!

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.

Thanks! I like it, but errors can be tricky so I think we should refine this a little bit, mostly because you changes allows us to make the code even better :)

@@ -209,16 +209,19 @@ pub fn uu_app() -> Command {
)
}

fn open(path: &str) -> BufReader<Box<dyn Read + 'static>> {
fn open(path: &str) -> std::io::Result<BufReader<Box<dyn Read + 'static>>> {
Copy link
Member

Choose a reason for hiding this comment

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

It looks like this should return UResult instead, because then we don't have to show! the error immediately. You can look at the map_err_context method too for io errors, that allows us to add a context string and turn them in a UError.

To do this, you could split of all the code that could have write errors into a separate function that returns std::io::Result and then call that with map_err_context in unexpand.

Some(&s) => s,
None => {
show!(USimpleError::new(
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we stop execution at this error? Either that, or if we can verify that it really never happens it should maybe be an unreachable! call.

Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/tail/truncate is no longer failing!

Copy link
Contributor

@sylvestre sylvestre left a comment

Choose a reason for hiding this comment

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

Sorry, it needs to be rebased (conflict)

@sylvestre
Copy link
Contributor

no activity for a while, closing

@sylvestre sylvestre closed this Nov 25, 2024
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.

4 participants