Skip to content

r.earthworks: use a temporary region to restore the user's region on exit#1743

Open
Valyrian-Code wants to merge 2 commits into
OSGeo:grass8from
Valyrian-Code:r.earthworks-use-temp-region
Open

r.earthworks: use a temporary region to restore the user's region on exit#1743
Valyrian-Code wants to merge 2 commits into
OSGeo:grass8from
Valyrian-Code:r.earthworks-use-temp-region

Conversation

@Valyrian-Code

Copy link
Copy Markdown
Contributor

Part of #1741. Same use_temp_region() pattern as #1742 (r.soillossbare).

In main(), r.earthworks saves the current region as source, changes the region while modeling each quadrant, and restores it in series(). On a normal run that works fine. But the finally block only registers cleanup of the temporary maps, it does not restore the region, so on an error between the region change and the series() restore the user can be left with a changed region (and the saved source region gets removed by the cleanup too).

Wrapping the region handling in gs.use_temp_region() at the start of main() restores the user's original region automatically on exit, including on error. It is additive: the existing source save/restore still drives the per-quadrant and cumulative extents.

In practice series() restores on the normal path, so this mainly hardens the error path. @baharmon, since this is your module, does this look reasonable to you? Happy to adjust.

…exit

The finally block in main() registers cleanup of temporary maps but does not
restore the computational region, so on an error between the region change and
the series() restore the user could be left with a changed region. Wrap the
region handling in gs.use_temp_region() so the original region is restored
automatically on exit, including on error.
Copilot AI review requested due to automatic review settings June 9, 2026 19:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

2 participants