Skip to content

d.correlate: exit on insufficient input and fix text line counter - #7485

Merged
echoix merged 2 commits into
OSGeo:mainfrom
Valyrian-Code:d.correlate-exit-on-insufficient-maps
Jun 20, 2026
Merged

d.correlate: exit on insufficient input and fix text line counter#7485
echoix merged 2 commits into
OSGeo:mainfrom
Valyrian-Code:d.correlate-exit-on-insufficient-maps

Conversation

@Valyrian-Code

@Valyrian-Code Valyrian-Code commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Description

d.correlate mishandled any input that was not exactly two maps:

  • With fewer than two maps it called error() and kept going, so it printed
    the 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 raised
    TypeError: can only concatenate str (not "int") to str on the second map
    pair (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 that
reports an error should not exit successfully, and passing three or more maps
crashed.

How has this been tested?

Built GRASS locally and ran d.correlate before and after the change:

  • 1 map: exited 0 with no output -> now exits with an error.
  • 2 maps: works (unchanged).
  • 3 maps: raised TypeError -> now runs without error.

Added scripts/d.correlate/tests/d_correlate_test.py with two regression
tests; they fail on the previous code and pass on the fixed code. 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 05:42
@github-actions github-actions Bot added Python Related code is in Python module display 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 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.correlate fails with fewer than two maps and runs with three maps.
  • Change <2 maps handling from gcore.error() to gcore.fatal() to ensure a non-zero exit.
  • Fix a variable reuse bug by renaming line to text_line for d.text labeling.

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.

Comment thread scripts/d.correlate/tests/d_correlate_test.py
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
Valyrian-Code force-pushed the d.correlate-exit-on-insufficient-maps branch from 94d868b to 5a12ea9 Compare June 3, 2026 05:46
@echoix
echoix merged commit 5528eb8 into OSGeo:main Jun 20, 2026
26 checks passed
@github-actions github-actions Bot added this to the 8.6.0 milestone Jun 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

display module Python Related code is in Python tests Related to Test Suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants