Skip to content

Update ensure_filter_type_is_valid upper bound enum. #5488

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bekadavis9
Copy link
Contributor

Update the upper bound in ensure_filter_type_is_valid to reflect the highest-possible filter_type enum.


[sc-65265]


TYPE: NO_HISTORY
DESC: Update ensure_filter_type_is_valid upper bound enum.

@bekadavis9 bekadavis9 requested a review from ypatia April 2, 2025 20:48
inline void ensure_filtertype_is_valid(uint8_t type) {
if (type > 18) {
if (type > 19) {
Copy link
Member

Choose a reason for hiding this comment

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

I definitely don't love seeing an un-named constant here, it will be tricky to remember this if another filter type is added.

Maybe we can add a variant to the enum class FilterType which is INTERNAL_FILTER_COUNT or something? This definitely works with enums which don't have values assigned, but maybe it will work here anyway.

Copy link
Member

Choose a reason for hiding this comment

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

Another way to ensure that this does not break in the future would be to claim that the type is invalid if and only if filter_type_str returns empty string. That buys some robustness against someone forgetting to update both of those functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

100% agree. It's been discussed in the past that all of these ensure_<enum_type>_is_valid methods should check on some constant so programmers aren't responsible for hopefully remembering to update them (if they even know about them). This is certainly worth a larger discussion offline. Note that this PR is just a one-off update after I noticed this method was out-of-date during a separate discussion.

Copy link
Member

Choose a reason for hiding this comment

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

Let's add a quick test here which just checks if (is_filter_type_valid(i)) { CHECK(filter_type_str(i) != constants::empty_string); }) and also the other direction. I think that's a good enough way of adding future robustness.

@bekadavis9 bekadavis9 force-pushed the rd/update-filter_type branch from d2a0708 to df31dd6 Compare April 3, 2025 14:59
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