d.correlate: exit on insufficient input and fix text line counter - #7485
Merged
echoix merged 2 commits intoJun 20, 2026
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds regression coverage for d.correlate and fixes two failure modes: exiting successfully with <2 maps and crashing when given 3+ maps.
Changes:
- Add tests to assert
d.correlatefails with fewer than two maps and runs with three maps. - Change
<2 mapshandling fromgcore.error()togcore.fatal()to ensure a non-zero exit. - Fix a variable reuse bug by renaming
linetotext_lineford.textlabeling.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| scripts/d.correlate/tests/d_correlate_test.py | Adds regression tests for <2 maps fatal behavior and 3+ maps crash prevention |
| scripts/d.correlate/d.correlate.py | Ensures fatal exit on invalid input and avoids variable reuse by renaming the d.text line counter |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
When given fewer than two maps, d.correlate called error() and then continued: it printed the message but exited successfully and produced no output. Use fatal() so it exits with an error instead. The per-pair text line counter was also reused as the file-iteration variable in "for line in ifile", which raised a TypeError on the second map pair (that is, with three or more maps). Rename the counter to text_line. Add a pytest regression test covering both cases.
Valyrian-Code
force-pushed
the
d.correlate-exit-on-insufficient-maps
branch
from
June 3, 2026 05:46
94d868b to
5a12ea9
Compare
echoix
approved these changes
Jun 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
d.correlatemishandled any input that was not exactly two maps:With fewer than two maps it called
error()and kept going, so it printedthe message but exited with a success code and produced no output. It now
calls
fatal()and exits with an error.The per-pair text line counter was reused as the file-iteration variable in
for line in ifile, which raisedTypeError: can only concatenate str (not "int") to stron the second mappair (that is, with three or more maps). The counter is renamed to
text_line.Motivation and context
Found while reviewing
d.correlate. Both are correctness bugs: a tool thatreports an error should not exit successfully, and passing three or more maps
crashed.
How has this been tested?
Built GRASS locally and ran
d.correlatebefore and after the change:TypeError-> now runs without error.Added
scripts/d.correlate/tests/d_correlate_test.pywith two regressiontests; they fail on the previous code and pass on the fixed code.
ruff formatandruff checkare clean.Types of changes