Skip to content

grass.pygrass: Raise GrassError in c_read_next_line when Vect_read_next_line fails - #7967

Open
bhuvan-somisetty wants to merge 1 commit into
OSGeo:mainfrom
bhuvan-somisetty:fix-7966-pygrass-c_read_next_line
Open

bhuvan-somisetty wants to merge 1 commit into
OSGeo:mainfrom
bhuvan-somisetty:fix-7966-pygrass-c_read_next_line

Conversation

@bhuvan-somisetty

Copy link
Copy Markdown
Contributor

Description

In python/grass/pygrass/vector/geometry.py, the c_read_next_line helper function previously executed a bare raise statement when ftype == -1 (when libvect.Vect_read_next_line encounters a read error or corrupted line). Because this statement was outside any active exception block, Python raised RuntimeError: No active exception to reraise.

This PR replaces the bare raise with raise GrassError(msg) to raise an informative GrassError when reading the next vector line fails, and adds unit tests to python/grass/pygrass/vector/testsuite/test_geometry.py.

Motivation and context

Fixes #7966.

How has this been tested?

Added unit tests in python/grass/pygrass/vector/testsuite/test_geometry.py testing that c_read_next_line raises GrassError on ftype == -1 and StopIteration on ftype == -2. Verified code formatting and lint checks using ruff check and ruff format.

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as before)

Checklist

  • PR title provides summary of the changes and starts with one of the pre-defined prefixes
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.

@github-actions github-actions Bot added Python Related code is in Python libraries tests Related to Test Suite labels Sep 28, 2026
@bhuvan-somisetty
bhuvan-somisetty force-pushed the fix-7966-pygrass-c_read_next_line branch from bd5584c to f656ac3 Compare September 29, 2026 21:23
…xt_line fails

In `python/grass/pygrass/vector/geometry.py`, `c_read_next_line` previously
executed a bare `raise` when `Vect_read_next_line` returned -1. Because this
occurred outside an active exception handler, Python raised a `RuntimeError`
indicating no active exception to reraise.

Fix this by explicitly raising `GrassError` with an informative error message
and add unit tests in `test_geometry.py`.

Fixes OSGeo#7966.

Signed-off-by: bhuvan-somisetty <somisettybhuvan5@gmail.com>
@bhuvan-somisetty
bhuvan-somisetty force-pushed the fix-7966-pygrass-c_read_next_line branch from f656ac3 to a64aa47 Compare September 29, 2026 21:49
@bhuvan-somisetty

Copy link
Copy Markdown
Contributor Author

Hi @echoix @ninsbl, whenever you get a chance, could you take a look at this one? It's a small fix, and all checks are green. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libraries Python Related code is in Python tests Related to Test Suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] grass.pygrass: Bare raise in c_read_next_line causes RuntimeError when ftype == -1

1 participant