Skip to content

Commit

Permalink
Use structured errors from libpolyline
Browse files Browse the repository at this point in the history
  • Loading branch information
urschrei committed May 13, 2024
1 parent 23448fc commit 839ba02
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ decoded_coords = decode_polyline(polyline, 5)
```

## Error Handling
Failure to encode coordinates, or to decode a supplied Polyline, will raise a `RuntimeError` which can be caught.
Failure to encode coordinates, or to decode a supplied Polyline, will raise a `RuntimeError` containing information about the invalid input.


## How it Works
Expand Down
2 changes: 1 addition & 1 deletion src/pypolyline/cutil.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def encode_coordinates(coords, int precision):
np.char.startswith(polyline, b"no longitude") or
np.char.startswith(polyline, b"couldn't")
):
raise RuntimeError("The input coordinates could not be encoded")
raise RuntimeError(polyline)
return polyline

def decode_polyline(bytes polyline, int precision):
Expand Down
3 changes: 1 addition & 2 deletions tests/test_pypolyline.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ def testDecodeBadPolyline(self):

def testEncodeBadCoordinates(self):
"""Test that bad Polylines throw the correct error"""
with pytest.raises(RuntimeError) as exc_info:
with pytest.raises(RuntimeError) as _:
cencode_coordinates(self.bad_coordinates, 6)
assert str(exc_info.value) == "The input coordinates could not be encoded"

# def testEncodeBadCoordinatesB(self):
# """Test that bad Polylines throw the correct error"""
Expand Down

0 comments on commit 839ba02

Please sign in to comment.