Skip to content

Fix valid index bug in getIndexDigit#1042

Merged
ajfriend merged 16 commits intouber:masterfrom
ajfriend:fix_digit_cli
Sep 8, 2025
Merged

Fix valid index bug in getIndexDigit#1042
ajfriend merged 16 commits intouber:masterfrom
ajfriend:fix_digit_cli

Conversation

@ajfriend
Copy link
Copy Markdown
Collaborator

@ajfriend ajfriend commented Sep 1, 2025

The following logic in the getIndexDigit CLI doesn't correctly identify invalid cells/vertexes/edges:

h3/src/apps/filters/h3.c

Lines 312 to 317 in 491eead

H3Error cellErr = H3_EXPORT(isValidCell)(cell);
H3Error edgeErr = H3_EXPORT(isValidDirectedEdge)(cell);
H3Error vertErr = H3_EXPORT(isValidVertex)(cell);
if (cellErr && edgeErr && vertErr) {
return cellErr;
}

This is because the isValid* functions return a boolean, not an H3Error code.

You can see the bad behavior with:

$ ./build/bin/h3 getIndexDigit -r 15 -c 5   # should fail
5

which should instead return an error.

@coveralls
Copy link
Copy Markdown

coveralls commented Sep 1, 2025

Coverage Status

coverage: 98.934%. remained the same
when pulling 6594726 on ajfriend:fix_digit_cli
into 491eead on uber:master.

@ajfriend
Copy link
Copy Markdown
Collaborator Author

ajfriend commented Sep 1, 2025

Alternatively, if we want to do this kind of validation, should we add it to the function directly? The downside would be the overhead of the check.

However, to me, it feels a little weird to have the extra validation in the CLI but not on the function itself. Or, does it make sense to do the extra validation for the CLI? Would it make sense to have the function and CLI be aligned in terms of how much validation they do?

Comment thread justfile Outdated
purge:
rm -rf build

test: build
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is this file intended to be checked in? The test commands seem specific to this change. If not, maybe gitignore it?

Copy link
Copy Markdown
Collaborator Author

@ajfriend ajfriend Sep 1, 2025

Choose a reason for hiding this comment

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

I'll remove it before landing.

I keep it in the git history because I often find myself referring to these files in old PRs after I haven't touched the repo in a while and need to remember how to do things. I find it is a good historical reference of what commands I was actually running at the time.

I also get a lot of value while working on a PR from seeing the diffs of this file over time.

Ideas on better ways to organize these somewhat personalized tooling files?

Copy link
Copy Markdown
Collaborator Author

@ajfriend ajfriend Sep 1, 2025

Choose a reason for hiding this comment

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

Also, I can ask questions like this: @isaacbrodsky, is this how you typically run tests in the repo? Do you tend to run ctest directly or commands like make test-fast? Do you know of a way to run just the CLI tests, or just one CLI test? Currently, ctest runs both the C and CLI tests.

:)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I usually run make test or make test-fast. When debugging in more detail I would switch to ctest since that provides more direct control and feedback about verbosity, print-on-error, etc. When debugging a specific failure I would then go to running the test binary directly, since I may need to run it under valgrind or lldb/gdb or something.

For the CLI tests I think I mainly run them through make test. For running a specific CLI test I would probably copy out the command from the applicable CMake file.

I don't have a recommendation on the specific commands ran. I feel this would be personal unless you document more about what the commands are and why someone would want to run them. For that I would either gitignore or keep in another branch or repo (as with dotfile repos). Unfortunately that loses the association with which uber/h3 commit they go. You could then try to use submodules to take care of that but my experience is most people find submodules challenging to work with.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks. For the justfile, I'll probably just stick to my plan of keeping it in the git history while developing, removing it before merging, and then squash merge at the end to keep the history clean.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could add it to .gitignore and then keep it in your local?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I like to keep it in the git history to see how it changes as I work on the diff, and also to be able to reference it later when I come back in a few months and I forget how to build everything. Removing at the last commit and then squashing (to remove it from the repo history) seems like a good compromise, but always open to other ideas!

Comment thread src/apps/filters/h3.c Outdated
Copy link
Copy Markdown
Collaborator

@isaacbrodsky isaacbrodsky left a comment

Choose a reason for hiding this comment

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

Please remove justfile before merging

This was referenced Sep 3, 2025
Comment thread src/apps/filters/h3.c
H3Error vertErr = H3_EXPORT(isValidVertex)(cell);
if (cellErr && edgeErr && vertErr) {
return cellErr;
bool isValid = H3_EXPORT(isValidCell)(cell) ||
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I see how I made this mistake. In most of the code the error condition is the "truthy" value, but here success is true, though I named these variables as if they were H3Errors. That feels like a point against Hungarian Notation.

@ajfriend
Copy link
Copy Markdown
Collaborator Author

ajfriend commented Sep 8, 2025

@ajfriend ajfriend merged commit 7f2d2f7 into uber:master Sep 8, 2025
45 checks passed
@ajfriend ajfriend deleted the fix_digit_cli branch September 8, 2025 15:25
Comment thread src/apps/filters/h3.c
@@ -309,11 +309,11 @@ SUBCOMMAND(getIndexDigit,
Arg *args[] = {&getIndexDigitArg, &helpArg, &cellArg, &digitArg};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@ajfriend should lines 265-268, 285-288, 391-394, and 420-423 be updated as well?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah, fixed in #1055

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Ah, good catch @LucaDiba! And thanks for the fix @justinhwang!

justinhwang added a commit to justinhwang/h3 that referenced this pull request Oct 9, 2025
@ajfriend ajfriend added this to the v4.4 milestone Oct 16, 2025
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.

6 participants