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

Avoid failed assertion when showing fixes from stdin #8029

Merged
merged 1 commit into from Oct 18, 2023

Conversation

charliermarsh
Copy link
Member

Summary

When linting, we store a map from file path to fixes, which we then use to show a fix summary in the printer.

In the printer, we assume that if the map is non-empty, then we have at least one fix. But this isn't enforced by the fix struct, since you can have an entry from (file path) to (empty fix table). In practice, this only bites us when linting from stdin, since when linting across multiple files, we have an AddAssign on Diagnostics that avoids adding empty entries to the map. When linting from stdin, we create the map directly, and so it is possible to have a non-empty map that doesn't contain any fixes, leading to a panic.

This PR introduces a dedicated struct to make these constraints part of the formal interface.

Closes #8027.

Test Plan

cargo test (notice two failures are removed)

@charliermarsh charliermarsh added bug Something isn't working cli Related to the command-line interface labels Oct 17, 2023
success: false
exit_code: 1
success: true
exit_code: 0
Copy link
Member Author

Choose a reason for hiding this comment

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

I think this is correct, and was wrong before.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed

@github-actions
Copy link

github-actions bot commented Oct 17, 2023

PR Check Results

Ecosystem

✅ ecosystem check detected no changes.

Comment on lines 160 to 162
pub(crate) fn is_empty(&self) -> bool {
self.0.values().all(FixTable::is_empty)
}
Copy link
Member

Choose a reason for hiding this comment

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

This is a somewhat expensive check for large fix tables. Can we instead avoid adding entries when they have no fixes or would that be confusing because it is no longer guaranteed that a key is present after inserting it.

Copy link
Member Author

Choose a reason for hiding this comment

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

We can... It puts us back in the world we were in before (we'll need to take more care when creating these). I was hoping to capture hide that detail from callers. But I can change it.

Copy link
Member

Choose a reason for hiding this comment

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

Can't we handle it inside of from_iter?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, right, I moved it.

@charliermarsh charliermarsh merged commit 195c000 into main Oct 18, 2023
16 checks passed
@charliermarsh charliermarsh deleted the charlie/fix-map branch October 18, 2023 01:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cli Related to the command-line interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Panic] check file from stdin
3 participants