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

v4 error handling #243

Open
ajfriend opened this issue May 25, 2022 · 1 comment
Open

v4 error handling #243

ajfriend opened this issue May 25, 2022 · 1 comment
Assignees
Labels

Comments

@ajfriend
Copy link
Contributor

ajfriend commented May 25, 2022

We'd like to simplify the error checking and handling in h3-py v4 by:

  • doing fewer correctness tests in Python/Cython code (as long as that won't allow for segfaults), deferring those correctness tests to the user (with the idea that they'd know better when those checks are and are not necessary)
  • pass through the H3 core error values and messages, rather than using custom Python error types and messages

For the initial v4.0 release, we might do something simple like have only a single H3 error type (as opposed to a class hierarchy of errors) that can take on various messages, and might programmatically expose the H3 core error enum.

PRs or Issues providing examples to consider

@ajfriend ajfriend added the v4 label May 25, 2022
This was referenced May 25, 2022
@ajfriend
Copy link
Contributor Author

One idea is to have a generic wrapper that captures and raises an error (from an H3 c library function that returns an error code), which also accepts extra arguments if that information would be useful to the user.

For example, the current Cython code:

cpdef int distance(H3int h1, H3int h2) except -1:
    """ Compute the grid distance between two cells
    """
    cdef:
        int64_t distance
        h3lib.H3Error err

    check_cell(h1)
    check_cell(h2)

    err = h3lib.gridDistance(h1, h2, &distance)
    if err:
        # todo: do error handling later
        s = 'Cells are too far apart to compute distance: {} and {}'
        s = s.format(hex(h1), hex(h2))
        raise H3ValueError(s)

    return distance

might instead look like:

cpdef int distance(H3int h1, H3int h2) except -1:
    """ Compute the grid distance between two cells
    """
    cdef:
        int64_t distance

    check_for_error(
        h3lib.gridDistance(h1, h2, &distance),
        h1,
        h2,
    )

    return distance

@ajfriend ajfriend self-assigned this May 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant