Skip to content

fix(layout): refuse a grid, scale bar or north arrow value of the wrong type - #3161

Merged
jgregoriorincon merged 2 commits into
opengeos:mainfrom
jgregoriorincon:fix/3110-typed-layout-values
Nov 28, 2026
Merged

jgregoriorincon merged 2 commits into
opengeos:mainfrom
jgregoriorincon:fix/3110-typed-layout-values

Conversation

@jgregoriorincon

@jgregoriorincon jgregoriorincon commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A grid, scale bar or north arrow option given with a value of the wrong type was ignored: the command succeeded and kept the value the element already had, or its default. It is now refused, naming the key and what it takes, with nothing changed.

  • The cause is that the shared readers ps and f answer "not given" for a type they don't read. They are left as they are (many commands rely on that); grid_params, restyle and orientation_of read these keys strictly instead.
  • Numbers (step, tickLength, width) go through the existing given_num. Names (type, style, format, labelOrientation, units) go through a small given_name beside given_choice, so the messages for an unknown name stay as they were.
  • This covers layout.addElement, layout.update and layout.publication, so every surface that runs them (desktop, browser, CLI, Python, the Assistant, tasks). The ribbon and the Format pane already send the right types; undo is unchanged, as a refusal leaves no step.
  • orientation_of is shared, so a colorbar's or chart's orientation of the wrong type is refused too.
  • null means not given (a scale bar's divisions, which refused it, included), and a number written as text ("5") is still read.
  • A caller that sent a wrong type before, an empty string for a number included, now gets an error.

Not in this PR: the true/false options (the command already says which it couldn't read) and the options of other elements.

Testing

  • New tests in crates/engine/src/tests/layout_typed_values.rs; the five that expect a refusal and the null one for divisions failed before their fix.
  • Full checks (fmt, clippy, nextest, doctests, layers, cargo xtask schema --check) passed on the first commit.
  • cargo nextest run -p rustgis-engine -E 'test(layout_typed_values) | test(layout) | test(hostile_params_never_panic)': 194 passed.
  • cargo clippy -p rustgis-engine --all-targets -- -D warnings and cargo fmt --all --check: clean.

UI evidence

No visible UI change.

Related issue

Closes #3110

Summary by CodeRabbit

  • Bug Fixes
    • Improved validation for layout settings, including grids, orientation, scale bars, north arrows, publication parts, and colorbars. Invalid values are rejected with clearer errors, and failed changes leave the project and undo history unchanged.
    • Null options continue to preserve existing settings. Numeric text and recognized grid styles remain accepted, while unknown grid styles are rejected.

@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Layout command readers now reject wrong-typed grid, scale-bar, north-arrow, and orientation values. Tests cover refusal, unchanged state, null options, and accepted values.

Changes: Layout option validation

Layer / File(s) Summary
Add typed readers to layout options
crates/engine/src/cmd/layout/chart.rs, crates/engine/src/cmd/layout/elements.rs, crates/engine/src/cmd/layout/frame.rs
A shared name reader distinguishes absent or null values from non-text values. Orientation and grid options use typed readers while retaining existing normalization, validation, and clamping.
Validate style updates and command outcomes
crates/engine/src/cmd/layout/update.rs, crates/engine/src/tests.rs, crates/engine/src/tests/layout_typed_values.rs
North-arrow and scale-bar updates use typed readers. Tests check wrong-typed values, command refusal without project or undo-label changes, null options, numeric strings, and unknown styles.

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix · Severity of issue fixed: Low

Possibly related issues

  • Issue 3094 concerns the grid, scale-bar, and north-arrow options in layout.publication. This change adds wrong-type validation for selected publication options.

Possibly related PRs

  • opengeos/RustGIS#2537: Adds chart appearance options, including orientation values that use the reader changed here.

Suggested reviewers: m-hollis-1, elpidioassinaturas

Merge Risk: Minimal · up to 30dad

Layout grid, scale bar, and north arrow options of the wrong type are now refused with a clear error instead of being silently ignored. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: a grid, scale bar or north arrow value of the wrong type is now refused instead of silently ignored. It matches the PR objectives and the linked issue #3110, and it fo…
Description check Passed The description follows the template. It has Summary, Testing, UI evidence and Related issue sections. The Summary explains the change and its cause. Testing lists new tests, the failing-before-fix te…
Linked Issues check Passed Issue #3110 requires that a grid or scale bar option with a wrong-type value be refused, naming the key and its expected type, with no change made. The change set covers this:
- grid_params (crates/…
Out of Scope Changes check Passed Every changed area ties to issue #3110 or to its stated root cause:
- ps and f are unchanged. The strict readers are added in grid_params, restyle, and orientation_of, as the issue describes…
Full details: Title check

Explanation

The title names the main change: a grid, scale bar or north arrow value of the wrong type is now refused instead of silently ignored. It matches the PR objectives and the linked issue #3110, and it follows the conventional commit style. The layout scope is stated.

Full details: Description check

Explanation

The description follows the template. It has Summary, Testing, UI evidence and Related issue sections. The Summary explains the change and its cause. Testing lists new tests, the failing-before-fix tests, and the commands run. UI evidence states no visible UI change, as the template allows. Related issue cites Closes #3110. The description is complete and specific.

Full details: Linked Issues check

Explanation

Issue #3110 requires that a grid or scale bar option with a wrong-type value be refused, naming the key and its expected type, with no change made. The change set covers this:

  • grid_params (crates/engine/src/cmd/layout/frame.rs) reads grid type, step, style, tickLength, width, and format through typed readers that take an expected-value description. This covers the issue examples "type": 17 and "step": "bad".
  • restyle (crates/engine/src/cmd/layout/update.rs) reads scale bar units with given_name and scale bar divisions with given_num. This covers "units": 17. The null case for divisions is handled as not given.
  • given_name (crates/engine/src/cmd/layout/chart.rs) returns an error with the caller's description for a non-text value. given_choice keeps its unknown-name errors.
  • The tests in crates/engine/src/tests/layout_typed_values.rs cover refusals for grid, scale bar, north arrow, publication part, and colorbar values. They also assert that a refusal leaves the project and undo label unchanged, and that null and numeric text are still accepted.

The issue names layout.addElement, layout.update, and layout.publication. The changed files reach these commands through grid_params, restyle, and orientation_of. No separate publication file is in the change set, so the publication path is confirmed only through its tests and the shared readers. The whole-PR diff was not read line by line; this verdict rests on the summary and the listed changes.

Full details: Out of Scope Changes check

Explanation

Every changed area ties to issue #3110 or to its stated root cause:

  • ps and f are unchanged. The strict readers are added in grid_params, restyle, and orientation_of, as the issue describes.
  • orientation_of is shared by colorbar and chart orientation. The PR states this and does not treat it as a separate feature, so the wider effect is a direct result of the root-cause fix.
  • given_choice now delegates text checks to given_name. Its error text for unknown names is unchanged, which keeps existing behavior.
  • crates/engine/src/tests.rs adds the new test module. The test file covers the new refusal behavior.
    The PR excludes true/false options and options of other elements, so it does not expand into those areas. No unrelated change was found in the summary.
Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks each grid and scale,
Rejects the types that miss the trail.
Null leaves the old values in place,
Good numbers keep their measured pace.
The undo label stays the same.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: a78fda59-1ad2-42fc-a731-ecc62e361228
Commits

Reviewing files that changed from the base of the PR and between 3e977ea and 30dadf2.

Files selected for processing: 6

  • crates/engine/src/cmd/layout/chart.rs
  • crates/engine/src/cmd/layout/elements.rs
  • crates/engine/src/cmd/layout/frame.rs
  • crates/engine/src/cmd/layout/update.rs
  • crates/engine/src/tests.rs
  • crates/engine/src/tests/layout_typed_values.rs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.

@github-actions

Copy link
Copy Markdown
Contributor

Code review

Reviewed the 6-file diff against pr-context/AGENTS.md and the surrounding layout code. I could not run the test suite (no shell here), so the claims below come from reading the code. Prior review threads: none, so no earlier concerns were left alone.

Bugs

  • tick_side (crates/engine/src/cmd/layout/elements.rs:691) is the sibling of orientation_of, which this PR fixes, but it still reads tickSide through ps. A colorbar given "tickSide": 17 is added with the default side and the command succeeds. This is the silent loss the PR removes, so I posted it inline as a bug with a suggested fix. Confidence: high that the behaviour is as described, medium that it belongs in this PR (it is outside the title's grid/scale bar/north arrow scope). Posted as a buffered inline comment.

Security

  • None found.

Performance

  • None found. The new readers are O(1) per key.

Quality

  • Out-of-scope readers in the same family still drop wrong types silently: valign, case and align in text.rs, direction in elements.rs around line 759, and shape in frame.rs line 6. I saw these only by grep, not line by line. The PR's "Not in this PR" note excludes other elements, so this is a follow-up, not a blocker. Confidence: medium.
  • Behaviour change, disclosed in the PR: an empty string for a number (step: "", tickLength: "") is now an error where it was ignored. The Format pane sends numbers, so I found no in-repo caller that breaks. Confidence: low that it matters. Worth a check of Assistant and Python callers that might send "".

AGENTS.md

  • No rule break found. Checked:
    • No unwrap, expect or panic in the non-test code.
    • No command or parameter keys added or renamed, so command-surface.txt is unaffected.
    • No change to what a project saves, so no schema update is needed.
    • The new error text follows the neighbouring format! pattern for engine errors.
  • Twins checked: addElement, layout.update and layout.publication all reach grid_params, restyle or orientation_of, and the new tests cover all three. orientation_of is shared by colorbar, chart and labelOrientation, so the fix reaches all three. The file-read twin list does not apply to these layout readers.

Change size

Compared with the base branch: the whole PR against main (merge base a50612c to PR head 30dadf2).

Measure Value
Files changed 6 (1 added, 5 modified, 0 removed, 0 renamed)
Size before 3.84 MB
Size after 3.84 MB
Total size change +6.1 KB
Path Before After Change
crates/engine/src/tests/layout_typed_values.rs 0 B 5.4 KB +5.4 KB
crates/engine/src/cmd/layout/chart.rs 24.6 KB 24.9 KB +359 B
crates/engine/src/cmd/layout/frame.rs 20.6 KB 20.8 KB +203 B
crates/engine/src/tests.rs 3.70 MB 3.70 MB +67 B
crates/engine/src/cmd/layout/update.rs 40.2 KB 40.2 KB +66 B
crates/engine/src/cmd/layout/elements.rs 52.7 KB 52.8 KB +35 B

@github-actions

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-3161/
Web app https://preview.rustgis.app/pr-3161/app/
Commit 30dadf2

GitHub Pages takes a minute or two to publish a new commit. Newer commits from the fork aren't published until a maintainer adds the preview label (once per commit).

@jgregoriorincon
jgregoriorincon added this pull request to the merge queue Nov 28, 2026
@jgregoriorincon

Copy link
Copy Markdown
Contributor Author

On the review's two follow-ups: tickSide and the frame shape were ignored this way before this PR and belong to other elements, so they go to their own issue. valign, case, align and direction already refuse a value of the wrong type.

Merged via the queue into opengeos:main with commit 179ff4c Nov 28, 2026
28 checks passed
@jgregoriorincon
jgregoriorincon deleted the fix/3110-typed-layout-values branch November 28, 2026 00:56
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.

[Bug]: Layout commands ignore a grid or scale bar value of the wrong type without a word

1 participant