Skip to content

r.semantic.label: exit with error when print target is missing - #7496

Merged
petrasovaa merged 3 commits into
OSGeo:mainfrom
Valyrian-Code:r.semantic.label-print-exit-code
Jun 25, 2026
Merged

petrasovaa merged 3 commits into
OSGeo:mainfrom
Valyrian-Code:r.semantic.label-print-exit-code

Conversation

@Valyrian-Code

Copy link
Copy Markdown
Contributor

Description

operation=print printed an error but exited successfully when the raster
map was not found, because print_map_semantic_label returned None on
OpenError and main() ignored its return value. The add/remove path returns
1 for the same missing-map condition and main() propagates it, so the
exit codes were inconsistent across operations:

r.semantic.label operation=print  map=doesnotexist   # printed ERROR, exit 0
r.semantic.label operation=add    map=doesnotexist …  # printed ERROR, exit 1

This makes print_map_semantic_label return a status (1 on a missing map,
0 otherwise) and has main() honor it, so all operations exit consistently.

Motivation and context

A tool that reports ERROR: Map <…> not found should not exit 0 — scripts and
pipelines rely on the exit code. The add/remove path already does the right
thing; this aligns print with it.

How has this been tested?

Reproduced locally before and after the change. Added a regression test
(scripts/r.semantic.label/tests/r_semantic_label_test.py): print on a
missing map now raises (fails on the previous code, passes on the fix), and
print on an existing map without a label still succeeds. ruff format and
ruff check are clean.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • Tests

Copilot AI review requested due to automatic review settings June 3, 2026 18:00
@github-actions github-actions Bot added raster Related to raster data processing Python Related code is in Python module tests Related to Test Suite labels Jun 3, 2026

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.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds regression coverage and updates r.semantic.label to return a non-zero exit code when operation=print is run on a missing raster map, aligning it with add/remove behavior.

Changes:

  • Add tests covering operation=print behavior for missing vs existing maps.
  • Make print_map_semantic_label() return a status code and propagate failures from main().

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
scripts/r.semantic.label/tests/r_semantic_label_test.py Adds regression tests to ensure missing-map print fails and existing-map print succeeds.
scripts/r.semantic.label/r.semantic.label.py Returns explicit status from print_map_semantic_label() and propagates failures to module exit code.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

operation=print printed an error but exited successfully when the raster map was not found, because print_map_semantic_label returned None on OpenError and main() ignored it. The add/remove path returns 1 for the same condition and main() propagates it. Make print return a status (1 on a missing map, 0 otherwise) and have main() honor it, so all operations exit consistently.

Add a regression test.
@Valyrian-Code
Valyrian-Code force-pushed the r.semantic.label-print-exit-code branch from 8b92a26 to 23ac67e Compare June 3, 2026 18:11
@Valyrian-Code

Copy link
Copy Markdown
Contributor Author

Heads up for reviewers: the failing pytest check is from the r.param.scale reference test, not this PR, which only touches r.semantic.label. That test was added recently (#7534/#7584) and is known to be flaky across platforms.

Even main passes and fails intermittently on the same workflow due to the OpenMP issue tracked in #1168. The py3.10 job also hung for ~80 minutes, which matches the same problem.

A re-run should fix it, but I can rebase if preferred.

@Valyrian-Code

Copy link
Copy Markdown
Contributor Author

Thanks Anna, done. The test now catches ToolError from grass.tools instead of CalledModuleError.

@petrasovaa petrasovaa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks!

@petrasovaa
petrasovaa merged commit d23b59e into OSGeo:main Jun 25, 2026
26 checks passed
@github-actions github-actions Bot added this to the 8.6.0 milestone Jun 25, 2026
ninsbl pushed a commit to ninsbl/grass that referenced this pull request Jul 7, 2026
…#7496)

operation=print printed an error but exited successfully when the raster map was not found, because print_map_semantic_label returned None on OpenError and main() ignored it. The add/remove path returns 1 for the same condition and main() propagates it. Make print return a status (1 on a missing map, 0 otherwise) and have main() honor it, so all operations exit consistently.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module Python Related code is in Python raster Related to raster data processing tests Related to Test Suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants