Skip to content

HF-131 (2/7): the origin/propagation mechanism, plus the same guarantee outside the interpreter - #1762

Open
marcin-kordas-hoc wants to merge 34 commits into
feat/hf-131-error-messagesfrom
feat/hf-131-error-messages-outside-interpreter
Open

marcin-kordas-hoc wants to merge 34 commits into
feat/hf-131-error-messagesfrom
feat/hf-131-error-messages-outside-interpreter

Conversation

@marcin-kordas-hoc

@marcin-kordas-hoc marcin-kordas-hoc commented Sep 10, 2026 •

Copy link
Copy Markdown
Collaborator

Context

The PR records where each cell error came from, and gives the remaining cell errors outside the interpreter a message. It is part 2 of 7 of HF-131, stacked on #1761.

  • Why: a cell that read a parse error or a typed-in error reported its own address as the error's address. 19 cell errors built outside src/interpreter/ still had no message.
  • What changed:
    • hyperformula/src/Cell.ts: CellError gains originFunction, argumentIndex, propagated, originAddress and originAddressVersion, each set by a first-wins method that returns a new instance.
    • hyperformula/src/interpreter/Interpreter.ts: evaluateAst stamps originFunction once per AST node, and an error read from another cell no longer gets the reading cell as its root.
    • hyperformula/src/DependencyGraph/DependencyGraph.ts: getCellValue marks every error it reads from another cell as propagated. For a cell that holds a static error, it also records that cell's address and the current transformation version.
    • hyperformula/src/Exporter.ts, hyperformula/src/LazilyTransformingAstService.ts: the recorded address is moved through the row and column changes made since. Before a compaction discards those changes, DependencyGraph.forceApplyPostponedTransformations moves the addresses of the errors cached in formula vertices, including array results, to the current version.
    • hyperformula/src/Operations.ts: the change list from setCellContents carries a typed or unparsable error with the address getCellValue reports for it.
    • hyperformula/src/dependencyTransformers/CleanOutOfScopeDependenciesTransformer.ts: a pasted reference that falls off the sheet reports ErrorMessage.OutOfSheet; the base Transformer keeps ReferenceRemoved for removed rows and columns.
    • originFunction for an operator is the operator as written (+, -, *, /, ^, &, %, =, <>, <, >, <=, >=).
    • Parser (11), dependency transformers (4), Evaluator.ts (2 #CYCLE!), DependencyGraph.ts (1) and FormulaVertex.ts (1): each error gets an ErrorMessage constant. The lint rule from HF-131 (1/7): every interpreter cell error carries a message #1761 now covers all of src/.
    • hyperformula/test/_setupFiles/matchers/cellErrorComparison.ts: the Jest and Jasmine toEqualError matchers share one comparison.
    • hyperformula/src/parser/ParserWithCaching.ts: an error node's cache key ends with its message, except for an error typed into the formula, so a typed #REF! and a reference left by a removed row or column no longer share one cached formula and one message.
  • Result:
Sheet Read Before (develop) After
A1: =1+, B1: =A1 B1 address Sheet1!B1 Sheet1!A1
A1: #REF! typed, B1: =A1 B1 address Sheet1!B1 Sheet1!A1
A1: #REF! typed A1 address none Sheet1!A1
A1: #REF! typed, B1: =A1, then a row added above B2 address Sheet1!B2 Sheet1!A2
A1: #VALUE! typed, B1: =A1, then 50 rows added on Sheet2 B1 address Sheet1!B1 Sheet1!A1
B1: =A1, setCellContents puts #VALUE! in A1 A1 change address none Sheet1!A1
A1: =10^308*10 A1 address none Sheet1!A1
B1: =A1 copied and pasted into A1 A1 message '' Resulting reference is out of the sheet.
A1: =B1, B1: =A1 A1 message '' Cell is part of a circular reference.
A1: =#REF!, A2: =C2, then column C removed A2 message '' Reference points to a row or column that was removed.

originFunction and argumentIndex stay internal here; #1764 exposes them.

How did you test your changes?

  • Paired tests: handsontable/hyperformula-tests#60 on feat/hf-131-error-messages-outside-interpreter, with unit/Cell.spec.ts and new cases in unit/error-address-preservation.spec.ts, unit/error-messages.spec.ts, unit/parser/parser.spec.ts and unit/parser/parser-caching.spec.ts. verifyValues in unit/testUtils.ts aligns only the ReferenceRemoved to ErrorLiteral message change that a save and reload makes, and compares every other field.
  • Cell.spec.ts, error-address-preservation.spec.ts, parser.spec.ts and parser-caching.spec.ts pass against this head (136 tests). The four parser-caching.spec.ts cases fail on this head without the ParserWithCaching.ts change.
  • Undoing each fix of this round fails its cases: the change-list address 4, the compaction move 3 (the array result 1 of them), OutOfSheet 1, the operator names 7.
  • Full Jest with the paired tests: 529 suites, 7244 passed, 3 skipped.
  • The lint rule fires in src/Evaluator.ts for a bare new CellError(ErrorType.CYCLE) and for an explicit undefined message.
  • Performance of the whole stack (HF-131 (7/7): documentation #1767's head against develop), npm run benchmark:write-to-file, three alternating rounds, measured before the merge with the monorepo develop: total median −0.24%. "Column ranges - add column" was slower in all three rounds, median +3.34% against a 1.91% base spread.
  • CI is green on this head.

AI assistance

Claude Code wrote the engine change in hyperformula/src, the toEqualError and Jest matcher support files, the CHANGELOG entry, the paired tests (handsontable/hyperformula-tests#60) and this description. Every commit on both branches, other than merges, carries its co-author line (engine 9 of 9, tests 8 of 8).

Compatibility with Excel and Google Sheets

Not applicable: error types and displayed values do not change. Only message and address of DetailedCellError do.

Public API changes

  • CellError (exported): five new optional constructor parameters and two readonly fields, originFunction and argumentIndex. The engine-only members (propagated, originAddress, originAddressVersion, withOrigin, withArgumentIndex, asPropagated, withOriginAddress, withRebasedOriginAddress) are tagged @internal, so the API reference leaves them out; the constructor signature still lists their parameters.
  • DetailedCellError.address of an error read from a cell that holds a static error is now that cell's address, not the reader's, also in the change list and after a compaction.

Out of scope and follow-ups

Types of changes

  • Breaking change (existing functionality no longer works as before) – agreed with the maintainers
  • New feature or improvement (a non-breaking change that adds functionality)
  • Bug fix (a non-breaking change that fixes an issue)
  • Additional language file, or a change to an existing language file (translations)
  • Change to the documentation

Related issues

  1. Part of Improve the formula error messages #1547 (HF-131).

Checklist


Note

Medium Risk
Touches core evaluation, dependency reads, export, and lazy AST transformation—behavior change for error address/message with broad formula-engine impact, though error types displayed to users stay the same.

Overview
Cell errors now carry origin metadata and descriptive messages, so DetailedCellError.address points at the cell that actually holds or produced the error (typed literals, parse failures, propagated refs) instead of the reader—or none for static errors.

CellError gains immutable helpers (withOrigin, asPropagated, withOriginAddress, etc.) for first-wins origin tracking. DependencyGraph.getCellValue marks cross-cell reads as propagated and snapshots address + transformation version for static-error cells; Exporter and LazilyTransformingAstService.applyTransformationsToAddress replay sheet edits to keep that address current through row/column changes and compaction.

Outside the interpreter, bare CellError constructions (parser, transformers, cycles, array bounds) now use ErrorMessage constants; ESLint no-restricted-syntax applies to all of src/**/*.ts. ParserWithCaching distinguishes otherwise identical #REF! nodes by message in the cache key. Jest/Jasmine toEqualError share one comparison module.

Reviewed by Cursor Bugbot for commit deeabba. Bugbot is set up for automated code reviews on this repo. Configure here.

marcin-kordas-hoc and others added 4 commits September 8, 2026 02:25
Reading another cell's value funnels through DependencyGraph.getCellValue, so
that is where an error now gets marked as propagated -- one choke point instead
of a marking at each interpreter case, which is what let three read paths
(named expressions, range reads via SimpleRangeValue, and getScalarValue's
aggregation callers) slip through an earlier attempt. getScalarValue delegates
to getCellValue rather than reading the address mapping itself, so its callers
inherit the mark instead of bypassing it.

wrapperForRootVertex then skips a propagated error, so the reading cell is no
longer attached as its root. A vertex holding a STATIC error has no
FormulaVertex to serve as a lazily-resolved root, so getCellValue stamps the
address it already has; CellError is immutable, so this copies rather than
mutating what is stored, which is what keeps the address correct across row and
column changes.

evaluateAst's overflow guard now assigns instead of returning early, so a
NaN/Infinity result reaches the same postprocessing as every other value and
gets a root like anything else -- previously =SQRT(-1) had neither.

Measured on this branch: A1='=1+' reports Sheet1!A1 where it reported no
address; B1='=A1' reports Sheet1!A1 where it reported its own address; the same
holds two hops out, through a range, and through a named expression; it follows
the cell across addRows; and =1/0 with a propagating SUM still reports A1.
Full private suite: 5 failed / 6157 passed, byte-identical to this worktree's
baseline (those 5 are a pre-existing branch-pinning mismatch in the test repo).
tsc and eslint clean.

Also consolidates the toEqualError matcher. It existed twice, once per runner,
with hand-copied logic and two strip lists that could drift -- and had drifted
in a way that made a change appear inert under Jest. The decision now lives in
one shared module both wrappers call with their own equality function, so there
is a single strip list to extend. Verified by short-circuiting the shared
module: 30 tests went red and came back green, proving Jest really reads it.
The Karma half could not be executed here (no browser in this environment).

NOT yet observable through the public API: originFunction and argumentIndex are
carried on CellError and stamped in evaluateAst, but DetailedCellError does not
expose them yet. Exposing them is one line plus a test migration -- 10
assertions in error-address-preservation.spec.ts, arrays.spec.ts and
matrix-plugin.spec.ts use plain toEqual, which no matcher edit reaches, and
they must NOT be moved to toEqualError because it also strips address, which is
exactly what those tests assert. That split is the natural PR boundary here.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Task 2 of the HF-131 explainability plan: the 19 CellError construction
sites outside src/interpreter/ (17) plus src/Evaluator.ts's two
explicit-undefined CYCLE sites that passed no message at all now do,
mirroring what Task 1 already did for src/interpreter/.

Seven new catalogue constants cover semantically distinct groups rather than
one generic REF/NAME sentence: a removed-reference in an existing formula
(Transformer.ts, 4 sites), an array's source cell being overwritten
(DependencyGraph.ts), a position outside an array's own computed bounds
(FormulaVertex.ts), an unresolved parser reference (FormulaParser.ts, 6
REF sites), a reference exceeding sheet size limits (FormulaParser.ts, 4
NAME sites), an error value typed directly into a formula (FormulaParser.ts,
1 site), and a circular reference (Evaluator.ts, 2 CYCLE sites).

No error type changed, no function signature changed, i18n/Cell.ts/
CellValue.ts/Exporter.ts/the DependencyGraph choke point untouched.

Originally attempted via prep-ship's autonomous pipeline; the run crashed
twice with an empty error at its own 'authoring AC specs' step (unrelated
to this diff — see the private-test patch README for the diagnosis). The
production src/ implementation it left behind was verified correct against
every constraint in the task file and kept; the pre-existing private-test
breakage it hadn't yet reached was fixed by hand.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Enforces the guarantee this PR's message-filling work establishes: a
message-less new CellError(...) construction under src/interpreter/ is now
a lint error. Two selectors — a bare one-argument call, and an explicit
literal undefined as the second argument (the exact shape the two CYCLE
sites in src/Evaluator.ts still use; Evaluator.ts is outside src/interpreter/
so this rule doesn't reach them yet, and is unaffected by this commit).

Verified: 0 lint errors on the full src/ tree (same pre-existing warning
count as before this commit — no new warnings). The rule was proven to
actually fire, not just parse, by temporarily reverting one src/interpreter/
plugin site to a bare 'new CellError(ErrorType.NUM)', observing the expected
lint error, then restoring it (git diff empty afterward).

Widened to all of src/ in the next PR in this stack
(feat/hf-131-error-messages-outside-interpreter).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Changes the override's files glob from src/interpreter/ to all of src/, so
the guard this PR's own message-filling work (and the earlier commit's
interpreter-only rule) establishes covers the whole engine, not just the
interpreter plugins.

Documents the one call site the rule structurally cannot catch:
CellContentParser.ts's CellContent.Error constructor keeps message optional
on purpose (its one no-message caller — a user typing e.g. #REF! literally
into a cell — has no engine-side cause to state), and the call
'new CellError(errorType, message)' is syntactically a two-argument
construction that passes the rule cleanly regardless of what the caller
actually passes.

Verified: 0 lint errors on the full src/ tree (same pre-existing warning
count as before this commit). The widened rule was proven to actually reach
files outside src/interpreter/ by temporarily reverting one CYCLE site in
src/Evaluator.ts to a bare 'new CellError(ErrorType.CYCLE)', observing the
expected lint error, then restoring it (git diff empty afterward).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@qunabu

qunabu commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

@cursor cursor Bot 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.

Stale Bugbot comment from a previous run.

Comment thread CHANGELOG.md Resolved
Comment thread .eslintrc.js Resolved
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
hyperformula-docs b297384 Commit Preview URL

Branch Preview URL
Dec 03 2026, 08:15 AM

…at/hf-131-error-messages-outside-interpreter

# Conflicts:
#	.eslintrc.js

@cursor cursor Bot 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.

Stale Bugbot comment from a previous run.

Comment thread src/Cell.ts Resolved
@github-actions

github-actions Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Performance comparison of head (b297384) vs base (fe17259)

                                     testName |    base |    head |  change
---------------------------------------------------------------------------
                                      Sheet A |  388.97 |  396.81 |  +2.02%
                                      Sheet B |   128.6 |  130.73 |  +1.66%
                                      Sheet T |  110.42 |   113.5 |  +2.79%
                                Column ranges |  413.18 |  423.25 |  +2.44%
                                Sorted lookup | 12717.2 | 12901.1 |  +1.45%
Sheet A:  change value, add/remove row/column |   12.96 |    14.4 | +11.11%
 Sheet B: change value, add/remove row/column |  110.25 |  134.57 | +22.06%
                   Column ranges - add column |  128.76 |  149.81 | +16.35%
                Column ranges - without batch |  393.91 |  443.01 | +12.46%
                        Column ranges - batch |  102.06 |  110.27 |  +8.04%

@cursor cursor Bot 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.

Stale Bugbot comment from a previous run.

@marcin-kordas-hoc marcin-kordas-hoc changed the title HF-131 (2/7): the same guarantee outside the interpreter HF-131 (2/7): the origin/propagation mechanism, plus the same guarantee outside the interpreter Sep 11, 2026
marcin-kordas-hoc and others added 2 commits September 14, 2026 09:10
A cell that holds a static error - a formula the parser rejected, or an error
value entered directly - has no formula vertex to resolve an address through, so
DependencyGraph.getCellValue records the address on the error value itself when a
dependent reads it. The reading cell caches that value and is not recomputed by a
row or column change that merely shifts it, so the recorded address went stale:
the dependent kept naming the pre-shift cell, which by then could be empty or hold
an unrelated value.

The record now carries the LazilyTransformingAstService version it was taken at,
and Exporter replays the intervening transformations over it, the same way an
error produced by a formula already resolves its address through its root vertex.
The replay reuses each transformation's own transformSingleAst with an empty node
rather than fixNodeAddress, because MoveCellsTransformer only moves an address
that lies inside the range being moved and that decision lives in transformSingleAst.

Once a compaction has discarded the transformations the record predates, the
address cannot be reconstructed; it is omitted rather than guessed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…ages-outside-interpreter

# Conflicts:
#	CHANGELOG.md
The list's own note says to add every new CellError field here once. This commit
adds originAddressVersion, which the address fix introduced, and the two fields
that were already missing: propagated and originAddress. All three are recorded by
the engine as it reads a value, so an expectation built by hand cannot know them —
the same reason root and address are already ignored.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

@Tobiadefami Tobiadefami left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good. Verified that propagated errors retain their original source and that static-error addresses follow cell moves and row changes.

marcin-kordas-hoc and others added 2 commits October 22, 2026 17:07
…omment without a ticket reference

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ide-interpreter

# Conflicts:
#	CHANGELOG.md
#	hyperformula/test/_setupFiles/matchers/cellErrorComparison.ts
marcin-kordas-hoc and others added 3 commits October 23, 2026 07:13
…ide-interpreter

CHANGELOG.md: the parent's file (develop's entries for #1738, #1755, #1769
and #1816), with this branch's entry replacing the parent's HF-131 Changed
entry as before, plus this branch's Fixed entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An error typed into a formula and a reference left by a removed row or
column both print #REF!, so they had the same cache key, and whichever was
cached first gave its message to the other. The hash of an error node now
ends with its message, except for the message of a typed error, so a typed
error still hashes the same as the formula text it was parsed from.

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

@Tobiadefami Tobiadefami left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

hyperformula/src/dependencyTransformers/Transformer.ts:111

suggestion: Pasting a formula whose relative reference falls off the sheet now reports a cause that didn't happen:

const hf = HyperFormula.buildFromArray([[null, '=A1']], {licenseKey: 'gpl-v3'})
hf.copy({start: {sheet: 0, row: 0, col: 1}, end: {sheet: 0, row: 0, col: 1}})
hf.paste({sheet: 0, row: 0, col: 0})
hf.getCellValue({sheet: 0, row: 0, col: 0}).message
// 'Reference points to a row or column that was removed.'

No row or column was removed; the reference landed before column A. CleanOutOfScopeDependenciesTransformer inherits this ReferenceRemoved from the base Transformer. Could that transformer report ErrorMessage.OutOfSheet instead, with a paired test for this paste?


hyperformula/src/Cell.ts:192

nit: The JSDoc says attachRootVertex skips a propagated error, but it doesn't: asPropagated().attachRootVertex(v) still sets root. The check is in wrapperForRootVertex in Interpreter.ts. Could the check move into attachRootVertex, or the comment name wrapperForRootVertex?

Comment thread hyperformula/src/Cell.ts Resolved
Comment thread CHANGELOG.md Resolved

@cursor cursor Bot 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.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit deeabba. Configure here.

vertex.setCellValue(this.rebaseOriginAddress(value))
}
} else if (vertex instanceof ArrayFormulaVertex) {
vertex.mapStoredErrors(error => this.rebaseOriginAddress(error))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Range caches skip origin rebase

Medium Severity

forceApplyPostponedTransformations rebases originAddress only on formula vertices, but aggregations such as SUM also cache a stamped CellError on RangeVertex. After compaction those range-cache stamps still name a discarded version, so a later recompute that hits the cache (a volatile in the same formula, or another argument changing) drops DetailedCellError.address.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit deeabba. Configure here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 32dcc09: the flush now clears the range caches, so the next read recomputes them from the cells and the error keeps its address.

@marcin-kordas-hoc

Copy link
Copy Markdown
Collaborator Author

On Transformer.ts:111: since deeabba, CleanOutOfScopeDependenciesTransformer reports ErrorMessage.OutOfSheet, so your paste gives Resulting reference is out of the sheet., and error-messages.spec.ts in hyperformula-tests#60 has that paste. On Cell.ts:192: the asPropagated JSDoc now names wrapperForRootVertex in Interpreter.ts, where the check is.

@Tobiadefami Tobiadefami left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Your fixes for the earlier points work. Two things before I approve: the open thread on range caches (DependencyGraph.ts:710) is real: =SUM(A1:A2)+C1 over a typed error loses its address after a compaction, where develop reported one, so it needs a fix or a known-limitations entry. And the branch needs feat/hf-131-error-messages merged in; the changelog line will conflict.

…ages-outside-interpreter

# Conflicts:
#	CHANGELOG.md

@handsontable-pr-review handsontable-pr-review Bot 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.

Warning

High risk: Touches core value-reading (DependencyGraph.getCellValue), the interpreter's error postprocessing, the parser cache hashing and the lazy-transformation replay used by every recalculation and structural operation; a mistake here propagates wrong error values, addresses or change events across the whole engine.

Full review: 1 potential issue(s).

Want a deeper review? Comment /review improve on its own line: a full review of the latest commit with an extra fix-oriented pass (about 2x the cost).

Comment on lines +632 to +636
const vertex = this.addressMapping.getCell(address)
const holdsAStaticError = vertex instanceof ParsingErrorVertex || vertex instanceof ValueCellVertex
return holdsAStaticError
? value.withOriginAddress(address, this.lazilyTransformingAstService.version()).asPropagated()
: value.asPropagated()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fresh CellError instance per read breaks identity-based change detection

Medium severity

getCellValue now returns a new CellError instance (withOriginAddress(...).asPropagated()) on every read of a static-error cell, instead of the cached instance stored in the vertex. Evaluator.recomputeVertex (Evaluator.ts L83-91) detects "value unchanged" by reference equality (newCellValue !== currentValue), so a formula like =A1 over a typed/parse error now produces a brand-new, non-identical instance on every recompute. Whenever such a cell is marked dirty but its result is semantically identical (structural change, unrelated dependency edit, volatile recalc), a spurious CellValueChange is emitted to getChanges()/change listeners and columnSearch.change is invoked, where previously the change was suppressed. This affects every formula that references a cell holding a typed or parse error.

Suggestion: Compare by value (e.g. a CellError equality covering type/message/root/originAddress) in recomputeVertex, or have getCellValue return a stable per-vertex stamped instance (cache the propagated copy on the vertex) so repeated reads yield the same object.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in ca23e25, 0beed80 and afccb1d: asPropagated makes the propagated copy of an error once, and getCellValue keeps the stamped copy of a typed-in or parse error per vertex, also across row and column changes, until the error changes, the stamped address no longer leads to the cell, or the pending transformations are flushed. A formula that reads the same error again is no longer reported as changed; tests#60 covers that for =1/0, RAND(), a typed-in error, a parse error and a row inserted above, and each of those specs fails without its fix. One case remains: after the pending transformations are flushed (by default after 50 structural changes), the next edit lists a formula that reads a typed-in or parse error once more, because the flush drops the stamps.

marcin-kordas-hoc and others added 7 commits November 18, 2026 04:47
…ages-outside-interpreter

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ages-outside-interpreter

# Conflicts:
#	CHANGELOG.md
#	hyperformula/dev-docs/INTERPRETER.md
…ages-outside-interpreter

# Conflicts:
#	CHANGELOG.md
An aggregate such as SUM caches its result on the range vertex, and that result
can be an error whose origin address belongs to a transformation version the
flush discards. Clearing the caches makes the next read recompute them, so the
error keeps its address.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every read of a cell that holds an error marks it propagated. A new copy per
read made a formula that reads the same error again look changed to the
evaluator, which compares values by identity, so the change list and
valuesUpdated reported it.

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

@handsontable-pr-review handsontable-pr-review Bot 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.

Note

Medium risk: Touches CellError propagation on the core cell-reading path; a defect here would misreport cell changes or error origins across the engine, but the change is small and targeted at error-value identity only.

Incremental review: 1 potential issue(s).

hyperformula/src/Cell.ts:248

WeakMap fix incomplete: errors given an origin address still allocate per read

Medium severity

The WeakMap in asPropagated (L223-228) only caches the propagated copy. Per the PR description, DependencyGraph.getCellValue marks every read error asPropagated and, for static errors (typed errors, parse errors), then records the origin address via withOriginAddress. The cached propagated copy never has originAddress set, so withOriginAddress on it always takes the allocating branch and returns a fresh instance on every read (and if the calls happen in the opposite order, withOriginAddress allocates a fresh uncached receiver first, defeating the WeakMap entirely). For cells holding static errors this reintroduces exactly the identity-based change-detection problem the WeakMap was added to fix: an unchanged error is reported as a changed cell on every re-evaluation/export.

Suggestion: Cache the composed result too: key the WeakMap on the original error and store the copy after withOriginAddress is applied (e.g. have getCellValue build the propagated+addressed instance once and cache it, or make withOriginAddress on a propagated error reuse a second WeakMap entry), so repeated reads of the same vertex yield the same object.

Want a deeper review? Comment /review improve on its own line: a full review of the latest commit with an extra fix-oriented pass (about 2x the cost).

marcin-kordas-hoc and others added 2 commits November 25, 2026 14:15
…n hold

A typed-in or parse error gets its address stamped on every read, and a
parsing-error vertex builds a new error each time, so a formula that read the
same error again was reported as changed. The stamped copy is now kept per
vertex and reused until the error, the address or the transformation version
changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The stamp records the address with its transformation version, and readers
carry it forward the same way, so it stays valid while the carried address is
the cell's own. Re-stamping after every structural change made the first later
edit report the reading formulas as changed. Flushing the transformations drops
the stamps, since they could no longer be carried forward.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@marcin-kordas-hoc

Copy link
Copy Markdown
Collaborator Author

Fixed in 32dcc09: flushing the pending transformations now clears the range caches, so =SUM(A1:A2)+C1 over a typed error in A1 reports Sheet1!A1 again when it is recomputed after the flush. tests#60 has a spec for that sequence, which fails without the fix. feat/hf-131-error-messages is merged in acc1b29, and the full Jest suite passes.

marcin-kordas-hoc and others added 2 commits November 26, 2026 03:28
The cache entry now holds the address and transformation version the error
was stamped at, so the reuse check no longer reads them back from the error
and needs no branch for a missing origin.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ages-outside-interpreter

# Conflicts:
#	CHANGELOG.md

@Tobiadefami Tobiadefami left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The range-cache and stamp fixes work: typed and parse errors keep their own cell through moves, row changes, undo and compaction. One blocker: the merge duplicated the breaking-change entries in the changelog. One suggestion on error literals.


hyperformula/src/interpreter/Interpreter.ts:305

suggestion: An error written into the formula has no origin of its own, so the first function or operator around it claims it: =SUM(#N/A) records SUM, =#DIV/0!+1 records +, and =SUM(C1) after column C is removed records SUM. =#N/A alone records nothing. That goes against the withOrigin JSDoc ("an outer function that merely received the error back does not claim it"), and once #1764 exposes originFunction, users would see SUM blamed for an error it only passed on.

Could the ERROR / ERROR_WITH_RAW_INPUT nodes be their own origin, so later withOrigin calls leave them alone? A spec for =SUM(#N/A) and one for a removed reference inside SUM would pin it.

Comment thread CHANGELOG.md Outdated
Comment on lines +25 to +34
- Changed the cell errors produced while evaluating a formula to carry a message describing their cause. [#1547](https://github.com/handsontable/hyperformula/issues/1547)
- **Breaking change**: Changed `TEXT` to read a mask with `decimalSeparator` and `thousandSeparator`: with `','`, write `"0,00"`, not `"0.00"`, to get `1,50`. See the [migration guide](https://hyperformula.handsontable.com/docs/guide/migration-from-3.x-to-4.0.html). [#1716](https://github.com/handsontable/hyperformula/pull/1716)
- **Breaking change**: Changed `TEXT` to return `#VALUE!` for a mask with an unclosed `[` or `"`, a `[` followed by `]` or `\`, or a final `\`; escape it, as in `0\[`. See the [migration guide](https://hyperformula.handsontable.com/docs/guide/migration-from-3.x-to-4.0.html). [#1716](https://github.com/handsontable/hyperformula/pull/1716)
- **Breaking change**: Changed `TEXT` to read `,` as grouping by default and `#` as an optional digit: `=TEXT(5, "0,000")` returns `0,005`; use `"0\,000"` for `5,000`. See the [migration guide](https://hyperformula.handsontable.com/docs/guide/migration-from-3.x-to-4.0.html). [#1716](https://github.com/handsontable/hyperformula/pull/1716)
- **Breaking change**: Changed `stringifyDateTime` and `stringifyDuration` to get the mask without its color tag, such as `[Red]`, and not to run when `TEXT` returns `#VALUE!`. See the [migration guide](https://hyperformula.handsontable.com/docs/guide/migration-from-3.x-to-4.0.html). [#1716](https://github.com/handsontable/hyperformula/pull/1716)
- **Breaking change**: Added the `#CALC!` error, which `FILTER` and `UNIQUE` now return instead of `#N/A` when the result would be an empty array, `SEQUENCE` returns instead of `#VALUE!` when the number of rows or columns truncates to 0 (e.g. `=SEQUENCE(0)`), and `CONCAT` and `TEXTJOIN` return instead of `#VALUE!` when the result is longer than 32,767 characters, as in Microsoft Excel. `IFNA()` and `ISNA()` no longer catch these errors; use `IFERROR()` or `ISERROR()`. A custom language pack must now translate the `CALC` error, or `registerLanguage()` throws a `MissingTranslationError`. See the [migration guide](https://hyperformula.handsontable.com/docs/guide/migration-from-3.x-to-4.0.html). [#1647](https://github.com/handsontable/hyperformula/issues/1647)
- **Breaking change**: Changed the `INDEX` function to match Microsoft Excel. A row or column past the range now returns `#REF!` instead of `#NUM!`, a fractional row or column is truncated, and a row or column of `0` returns the whole column or row, which spills. Without a column number, `INDEX` returns `#REF!` for a range with more than one row and column instead of using its first column, returns the whole row of an array with more than one row and column, and counts along a one-row range. `INDEX` also accepts the `area_num` argument. See the [migration guide](https://hyperformula.handsontable.com/docs/guide/migration-from-3.x-to-4.0.html). [#1544](https://github.com/handsontable/hyperformula/issues/1544)
- **Breaking change**: Changed the `FILTER` function to return `#VALUE!` for text in its `include` argument, including the empty text and `"TRUE"`, and to return an error found there, as in Microsoft Excel. Before, it dropped those rows, or kept them for `"TRUE"`. For example, a condition column of `=IF(B1>0, TRUE(), "")` now makes `FILTER` return `#VALUE!`; return `FALSE()` instead of `""`. See the [migration guide](https://hyperformula.handsontable.com/docs/guide/migration-from-3.x-to-4.0.html). [#1891](https://github.com/handsontable/hyperformula/pull/1891)
- **Breaking change**: Changed the Polish name of `PDURATION` from `ROCZ.PRZYCH` to `O.CZAS.TRWANIA` and the Turkish name of `VALUE` from `DEĞER` to `SAYIYAÇEVİR`, as in Microsoft Excel, which uses `ROCZ.PRZYCH` for `DURATION` and `DEĞER` for `PRICE`. A Polish or Turkish formula with an old name now calls `DURATION` or `PRICE`; use the new names instead. See the [migration guide](https://hyperformula.handsontable.com/docs/guide/migration-from-3.x-to-4.0.html). [#1848](https://github.com/handsontable/hyperformula/pull/1848)
- Changed the cell errors the engine produces, including invalidated references, circular references and error values typed into a formula, to carry a message describing their cause. [#1547](https://github.com/handsontable/hyperformula/issues/1547)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

blocking: The merge of feat/hf-131-error-messages brought back seven Breaking change entries that are already above (TEXT ×4, #CALC!, INDEX, FILTER, PDURATION), so each would be listed twice. The copies are the older versions: they link the old migration guide URL, and the #CALC! one still says CONCAT and TEXTJOIN returned #VALUE!, which #1922 removed.

Could you delete the copies (lines 26–33) and fold the second #1547 line into the first, so #1547 has one entry?

marcin-kordas-hoc and others added 3 commits November 29, 2026 14:45
…1547 entry

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An ERROR or ERROR_WITH_RAW_INPUT node holds an error that no function or
operator produced: a typed error value, or the #REF! a reference turns into
once its row, column or sheet is removed. First-occurrence-wins let the first
function or operator around it claim it, so `=SUM(#N/A)` reported SUM and
`=#DIV/0!+1` reported `+`.

The interpreter now marks such an error origin-locked when it evaluates the
node, and `withOrigin` leaves a locked error alone. A separate internal flag
is used rather than `propagated`, because a propagated error is not given the
evaluating cell as its root, which would move where a typed error is
reported. The locked copy is made once per error, as the propagated copy is,
so re-evaluating a formula does not produce a new object.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The lock also applies to the error the parser builds for a reference it
cannot resolve or one beyond the sheet size limits. A reference to a removed
sheet is not an error node, so it is not covered.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@marcin-kordas-hoc

Copy link
Copy Markdown
Collaborator Author

On the Interpreter.ts:305 suggestion: errors from ERROR / ERROR_WITH_RAW_INPUT nodes (typed error values and the #REF! a removed row or column leaves) are now locked with no origin when evaluated, so =SUM(#N/A), =#DIV/0!+1 and =SUM(C1) after removing column C record none, while =SQRT(-1) still records SQRT; each case has a spec. A reference to a removed sheet stays a reference and is still attributed to the reading function.

@Tobiadefami Tobiadefami left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Both earlier points are fixed, thanks. Two new ones in the stamp cache and the change list, plus a description fix.

Comment on lines +646 to 670
const version = this.lazilyTransformingAstService.version()
const cached = this.stampedStaticErrors.get(vertex)
if (
cached !== undefined
&& (vertex instanceof ParsingErrorVertex || cached.source === value)
&& this.stampedAddressStillHolds(cached, address, version)
) {
return cached.stamped
}
const stamped = value.withOriginAddress(address, version).asPropagated()
this.stampedStaticErrors.set(vertex, {source: value, stamped, address, version})
return stamped
}

/**
* Whether a stamp still names `address`: the address it was stamped with, carried through
* the transformations since its version, is `address`. Exporter carries it the same way, so the
* old stamp reports the right cell and can be reused across row and column changes.
*/
private stampedAddressStillHolds(stamp: { address: SimpleCellAddress, version: number }, address: SimpleCellAddress, version: number): boolean {
const current = stamp.version === version
? stamp.address
: this.lazilyTransformingAstService.applyTransformationsToAddress(stamp.address, stamp.version)
return current !== undefined && equalSimpleCellAddress(current, address)
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

suggestion: When the cached stamp still holds, its entry keeps the old version, so once any transformation is pending every read of a typed or unparsable error cell replays all of them (up to 49 with the default maxPendingLazyTransformations). With 20,000 typed #N/A in A1:A20000, B1: =SUMPRODUCT(--ISERROR(A1:A20000))+C1 and 49 addRows on another sheet, five setCellContents(C1) take 155 ms, against 4 ms on the base branch.

Moving the entry forward before returning should fix it:

cached.address = address
cached.version = version
return cached.stamped

The stamped error keeps its own originAddressVersion, so Exporter still replays from the right point.

// A typed error value is read back through the dependency graph so the change carries the
// same address that getCellValue() reports for this cell.
this.changes.addChange(value.parsedValue instanceof CellError ? this.dependencyGraph.getCellValue(address) : value.parsedValue, address)
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

suggestion: In a batch (or suspendEvaluation) where a typed error is set and a later structural change triggers a compaction, the error's entry in the change list loses its address. forceApplyPostponedTransformations rebases the errors cached in formula vertices, but not the ones already waiting in the change list.

const engine = HyperFormula.buildFromSheets({Sheet1: [[null, '=A1']], Sheet2: [[1]]})
for (let i = 0; i < 49; i++) engine.addRows(1, [0, 1])
const changes = engine.batch(() => {
  engine.setCellContents(adr('A1'), '#VALUE!')
  engine.addRows(1, [0, 1])
})

The change for A1 has address === undefined, while B1's change and getCellValue(A1) give Sheet1!A1. The description says the address holds "also in the change list and after a compaction", so either rebase the pending changes there too, with a spec for a batch that compacts, or narrow that sentence.

Comment thread hyperformula/src/Cell.ts
Comment on lines 164 to 179
constructor(
public readonly type: ErrorType,
public readonly message?: string,
public readonly root?: FormulaVertex
public readonly root?: FormulaVertex,
public readonly originFunction?: string,
public readonly argumentIndex?: number,
/** @internal */
public readonly propagated: boolean = false,
/** @internal */
public readonly originAddress?: SimpleCellAddress,
/** @internal */
public readonly originAddressVersion?: number,
/** @internal */
public readonly originLocked: boolean = false,
) {
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: The description's Public API section says five new optional constructor parameters; with originLocked from the error-literal fix there are six. originLocked and asOriginLocked are also missing from the @internal list.

marcin-kordas-hoc and others added 3 commits December 3, 2026 07:55
A stamp that still names the right cell kept the version it was made at,
so every later read of a typed-in or parse error replayed all pending
row and column changes again. The entry now takes the current address and
version when it is reused, so the next read compares it directly.

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

An error typed into a cell, or a formula that cannot be parsed, set
earlier in a batch is already in the change list when the compaction at
the end of the batch discards the stored transformations. Its origin
address is now moved to the current version first, so the exported change
reports the cell instead of no address.

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

codecov Bot commented Dec 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.02913% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.10%. Comparing base (fe17259) to head (b297384).

Files with missing lines Patch % Lines
hyperformula/src/Cell.ts 97.50% 1 Missing ⚠️
...yperformula/src/DependencyGraph/DependencyGraph.ts 97.72% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@                      Coverage Diff                       @@
##           feat/hf-131-error-messages    #1762      +/-   ##
==============================================================
+ Coverage                       97.06%   97.10%   +0.04%     
==============================================================
  Files                             212      212              
  Lines                           19334    19500     +166     
  Branches                         4597     4652      +55     
==============================================================
+ Hits                            18767    18936     +169     
+ Misses                            567      541      -26     
- Partials                            0       23      +23     
Files with missing lines Coverage Δ
hyperformula/src/CellContentParser.ts 100.00% <ø> (ø)
hyperformula/src/ContentChanges.ts 100.00% <100.00%> (ø)
hyperformula/src/DependencyGraph/FormulaVertex.ts 85.71% <100.00%> (+0.98%) ⬆️
hyperformula/src/Evaluator.ts 100.00% <100.00%> (ø)
hyperformula/src/Exporter.ts 90.24% <100.00%> (+0.91%) ⬆️
hyperformula/src/HyperFormula.ts 97.41% <100.00%> (+<0.01%) ⬆️
hyperformula/src/LazilyTransformingAstService.ts 98.24% <100.00%> (+0.37%) ⬆️
hyperformula/src/Operations.ts 99.11% <100.00%> (ø)
...sformers/CleanOutOfScopeDependenciesTransformer.ts 100.00% <100.00%> (ø)
...rformula/src/dependencyTransformers/Transformer.ts 98.73% <100.00%> (+1.36%) ⬆️
... and 6 more

... and 7 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@handsontable-pr-review handsontable-pr-review Bot 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.

Warning

High risk: Touches core runtime paths — DependencyGraph.getCellValue, recalculation/compaction in HyperFormula, and the parser cache key — so defects here affect every formula evaluation and change export.

Incremental review: 1 potential issue(s).

hyperformula/src/DependencyGraph/DependencyGraph.ts:769

Unresolvable origin address survives compaction when origin cell was removed

Low severity

rebaseOriginAddress returns the error unchanged when applyTransformationsToAddress yields undefined (the origin cell was deleted by a row/column removal). The error then keeps its pre-compaction originAddress and originAddressVersion, but compactLazyTransformationsIfNeeded immediately discards the transformation history via compact(), so Exporter can no longer replay that version: the recorded address either resolves against the wrong version or not at all, and the exported change reports a stale address for a cell that no longer exists. This happens exactly in the scenario the feature targets (a reference left by a removed row/column).

Suggestion: When the transformed address is undefined, clear the origin address (or re-stamp from the reading cell) instead of returning the error with a version that is about to be discarded.

Want a deeper review? Comment /review improve on its own line: a full review of the latest commit with an extra fix-oriented pass (about 2x the cost).

This branch has not been deployed

No deployments
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.

3 participants