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

Introduce Error Codes #63

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

Introduce Error Codes #63

wants to merge 1 commit into from

Conversation

charlespnh
Copy link

@charlespnh charlespnh commented Dec 1, 2023

Introducing error codes from H3 v4. and Go error into APIs return signature.

Release note: breaking changes to almost all APIs.

@CLAassistant
Copy link

CLAassistant commented Dec 1, 2023

CLA assistant check
All committers have signed the CLA.

@coveralls
Copy link

coveralls commented Dec 2, 2023

Pull Request Test Coverage Report for Build 7999849463

Details

  • -52 of 252 (79.37%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-6.9%) to 88.287%

Changes Missing Coverage Covered Lines Changed/Added Lines %
h3.go 200 252 79.37%
Totals Coverage Status
Change from base Build 4495800687: -6.9%
Covered Lines: 505
Relevant Lines: 572

💛 - Coveralls

Copy link
Collaborator

@jogly jogly left a comment

Choose a reason for hiding this comment

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

thank you so much for your contribution, its looking great! there are only a few v small fixups needed to merge this. after you address comments, appease the linter, and run the files through gofmt it will be g2g!

h3.go Outdated
@@ -67,6 +67,59 @@ const (
RadsToDegs = 180.0 / math.Pi
)

var H3ErrorFailed = errors.New("Unknown error")
Copy link
Collaborator

Choose a reason for hiding this comment

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

In addition to the following lint warnings, can you group them in a var block like

var (
  ErrFailed = ...
  ErrDomain = ...
  ..
)

and update the error messages to start lowercase
https://github.com/golang/go/wiki/CodeReviewComments#error-strings

h3.go Outdated
var H3ErrorMemBound = errors.New("Memory bounds error")
var H3ErrorInvalidOption = errors.New("Invalid mode or flag error")

func New(errc int) error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
func New(errc int) error {
func errFromCode(errc int) error {

suggest unexport the error mapper as it is not relevant to consumers and rename to reflect that it maps from h3 error codes from C to Go

h3.go Outdated
Comment on lines 166 to 172
errc := C.latLngToCell(latLng.toCPtr(), C.int(resolution), &i)
if errc != C.E_SUCCESS {
return Cell(-1), New(int(errc))
}

return Cell(i)
return Cell(i), nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can inline the check into the conditional:

if rc := C.latLngToCell(latLng.toCPtr(), C.int(resolution), &i); rc != C.E_SUCCESS {
  return Cell(-1), errFromCode(int(rc))
}
return Cell(i), nil

I've also renamed errc to rc as it is a return code, not necessarily an error.


It's a fun idea to introduce sentinel values Cell(-1), but the error we return is sufficient signal that we can keep the amount of change low by continuing to return empty/undefined values on error.

h3.go Outdated
Comment on lines 1062 to 1077

var _ = H3ErrorFailed
var _ = H3ErrorDomain
var _ = H3ErrorLatLngDomain
var _ = H3ErrorResDomain
var _ = H3ErrorInvalidIndex
var _ = H3ErrorInvalidDirEdge
var _ = H3ErrorInvalidUnDirEdge
var _ = H3ErrorInvalidVertex
var _ = H3ErrorPentagon
var _ = H3ErrorDupInput
var _ = H3ErrorNeighbors
var _ = H3ErrorResMismatch
var _ = H3ErrorMemAlloc
var _ = H3ErrorMemBound
var _ = H3ErrorInvalidOption
Copy link
Collaborator

Choose a reason for hiding this comment

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

whats going on here?

h3_test.go Outdated
assertEqual(t, 2, len(gb), "edge has 2 boundary cells")
})
}
func testDirectedEdgeError(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
func testDirectedEdgeError(t *testing.T) {
func TestDirectedEdgeError(t *testing.T) {

h3_test.go Outdated
Comment on lines 455 to 477
_, err := Cell(0x891ea6d6533ffff).DirectedEdges()
assertTrue(t, errors.Is(err, H3ErrorInvalidDirEdge))

_, err = validCell.DirectedEdge(validDiskDist3_1[2][0])
assertTrue(t, errors.Is(err, H3ErrorNeighbors))

_, err = DirectedEdge(0).Origin()
assertTrue(t, errors.Is(err, H3ErrorInvalidDirEdge))
_, err = DirectedEdge(0x115283773fffffff).Origin()
assertTrue(t, errors.Is(err, H3ErrorFailed))

_, err = DirectedEdge(0).Destination()
assertTrue(t, errors.Is(err, H3ErrorInvalidDirEdge))
_, err = DirectedEdge(0x115283773fffffff).Destination()
assertTrue(t, errors.Is(err, H3ErrorFailed))

_, err = DirectedEdge(0).Cells()
assertTrue(t, errors.Is(err, H3ErrorInvalidDirEdge))
_, err = DirectedEdge(0x115283773fffffff).Cells()
assertTrue(t, errors.Is(err, H3ErrorFailed))

_, err = DirectedEdge(0x115283773fffffff).Boundary()
assertTrue(t, errors.Is(err, H3ErrorInvalidDirEdge))
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you pop the literal addresses into a named fixture var at the top of the file, similar to the other fixture vars? it helps us keep a handle on what these values mean.

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