Skip to content

Formula entry: an incomplete formula's error describes what was typed (fixes #2030) - #2032

Merged
aiongg merged 2 commits into
storytold:mainfrom
kezmdor:fix/2030-incomplete-formula-error
Oct 22, 2026
Merged

aiongg merged 2 commits into
storytold:mainfrom
kezmdor:fix/2030-incomplete-formula-error

Conversation

@kezmdor

@kezmdor kezmdor commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2030.

Entering an incomplete formula such as =1+ showed "There's a problem with this formula: unexpected )", although no ) was typed. Entry closes missing parentheses by appending up to eight ) and parsing again; when every retry failed, it reported the error of the last one. Now it reports the error of the formula as typed:

Typed Before After
=1+ unexpected ) unexpected end of formula
=-- unexpected ) unexpected end of formula
=SUM(1,+ unexpected ) unexpected end of formula
=SUM(1,(2+3 =SUM(1,(2+3)), 6 unchanged

Changes

  • gridcraft_formula::parse_closing_parens(src, parse) holds the convenience: parse as typed, then retry with up to eight ) appended, and return the first error if no retry parses. It takes the parse function, so cell entry (input_to_cell, English syntax) and the UI's Spanish formula path (formula_locale::canonical, parse_input) share it instead of each having its own loop.
  • No docs change: the parity docs don't describe entry error messages.

Tests

  • missing_closing_parentheses_are_closed_and_errors_describe_the_typed_text (formula): closing still works (SUM(1,2, ((1+2); for 1+, --, SUM(1,+, 1+*2 and nine unclosed ( the error equals the one for the typed text.
  • an_incomplete_formula_is_refused_with_an_error_about_what_was_typed (engine): =1+ and =SUM(1,+ through cell.set; fails on main with "unexpected )".
  • cargo xtask ci passes locally (Fedora 44, x86_64).
  • Checked in the desktop app over the control channel, with English and with Spanish formulas (View ▸ Español): =1+ and =SUMA(1;+ report "unexpected end of formula"; =SUMA(1;(2+3 still enters =SUM(1,(2+3)).

Notes

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved formula entry handling for expressions with missing closing parentheses.
    • Preserved automatic recovery for incomplete parentheses, allowing valid formulas to evaluate correctly.
    • Improved error reporting for incomplete expressions, such as formulas ending unexpectedly.
    • Ensured invalid formulas retain their original, clearer parse errors.

…fixes storytold#2030)

`=1+` reported "unexpected `)`", although no `)` was typed: entry closes
missing parentheses by appending up to eight `)`, and when every retry
failed it reported the last retry's error. It now reports the error of
the formula as typed ("unexpected end of formula").

`gridcraft_formula::parse_closing_parens` holds the convenience and takes
the parse function, so cell entry and the UI's Spanish formula path share
it instead of each having its own loop.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

⚙️ Run configuration
  • Configuration used: Repository: storytold/gridcraft/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 40b705a7-013b-4cfc-8466-987afd2ad224
📥 Commits

Reviewing files that changed from the base of the PR and between cfb0e18 and d1ab0ea.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 74567daf-c8d0-46b5-b5e7-186b9bb93910
📥 Commits

Reviewing files that changed from the base of the PR and between 23829d8 and cfb0e18.

📒 Files selected for processing: 6
  • crates/engine/src/cmd/edit.rs
  • crates/engine/src/tests.rs
  • crates/formula/src/lib.rs
  • crates/formula/src/parser.rs
  • crates/formula/src/tests.rs
  • crates/ui-egui/src/formula_locale.rs

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

📝 Walkthrough

Formula entry now uses a shared parser helper to retry formulas with up to eight appended closing parentheses. If retries fail, the helper returns the error from the formula as typed. Regression tests cover incomplete formulas and missing closing parentheses.

Changes: Formula recovery

Layer / File(s) Summary
Shared parser recovery
crates/formula/src/parser.rs, crates/formula/src/lib.rs, crates/formula/src/tests.rs
The formula crate adds and exports parse_closing_parens. It retries with up to eight closing parentheses and preserves the original parse error if all retries fail. Tests cover missing parentheses, valid formulas, and malformed input.
Formula entry integration
crates/engine/src/cmd/edit.rs, crates/ui-egui/src/formula_locale.rs, crates/engine/src/tests.rs
Engine and locale formula entry use parse_closing_parens instead of local retry loops. Engine tests check errors for incomplete formulas and successful recovery of missing closing parentheses.

Priority: ⬇️ Low

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

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: echelon, harrisonoconnorhover, nihilist-narwhal

Merge Risk: ⚪ Minimal · up to cfb0e

The supplied evidence identifies no actionable issue with formula-entry recovery; the change is ready for normal merge checks.

Security architecture risk: ⚪ Minimal · up to cfb0e

The shared helper preserves the existing recovery limit, parsing rules and entry controls. The intentional behavior change is to report the original input error when recovery fails. No material security risk was identified in this change.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — For the changed production callers, user-controlled formula text reaches the same parsers and downstream cell-construction path as before. The extracted API adds a library capability, but the compared entry paths do not gain new workbook targets, privileges or execution authority.

Trust Boundaries and Controls

  • observed — cell.set checks protected-cell restrictions before entering the edit operation. Formula detection, text-formatted-cell handling and argument-count validation remain outside the recovery helper. Localized canonicalization retains its existing stored user-defined-function preservation and workbook-name lookup behavior.

Resilience and Maintainability Implications

  • observed — Recovery attempts modify only a local string and return the first successful parse. Exhausted recovery propagates an error before formula construction, formula-driven style derivation or cell writes. The helper introduces no shared recovery state, reservation or cleanup step; successful cell updates retain their existing ordering.
Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly describes the main change: incomplete formula errors now describe the formula as typed. It is specific and related to the pull request objective.
Linked Issues check Passed The PR satisfies the coding requirements in directly linked issue #2030. parse_closing_parens parses the typed input first, retries with up to eight appended ), and returns the original parse erro…
Out of Scope Changes check Passed The reviewed changes stay within #2030. The shared parser helper, public re-export, call-site updates, and regression tests directly support consistent incomplete-formula errors and preserved closing-…
Docstring Coverage Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 6 files.
Full details: Linked Issues check

Explanation

The PR satisfies the coding requirements in directly linked issue #2030. parse_closing_parens parses the typed input first, retries with up to eight appended ), and returns the original parse error when all retries fail. input_to_cell and the Spanish formula_locale::canonical path both use this function. The added formula and engine regression tests cover the original error and preserved automatic closing behavior.

Full details: Out of Scope Changes check

Explanation

The reviewed changes stay within #2030. The shared parser helper, public re-export, call-site updates, and regression tests directly support consistent incomplete-formula errors and preserved closing-parenthesis recovery. No unrelated implementation or documentation change is shown.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aiongg
aiongg merged commit 6d4e62d into storytold:main Oct 22, 2026
1 check passed
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.

Formula entry: an incomplete formula reports "unexpected )" although no ) was typed

2 participants