Repository navigation
HF-131 (2/7): the origin/propagation mechanism, plus the same guarantee outside the interpreter - #1762
Conversation
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>
|
Task linked: HF-131 Verbose and actionable formula error messages |
Deploying with
|
| 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
Performance comparison of head (b297384) vs base (fe17259) |
…es-outside-interpreter
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
left a comment
There was a problem hiding this comment.
Looks good. Verified that propagated errors retain their original source and that static-error addresses follow cell moves and row changes.
…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
…ide-interpreter # Conflicts: # CHANGELOG.md
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
left a comment
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ 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)) |
There was a problem hiding this comment.
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.
Reviewed by Cursor Bugbot for commit deeabba. Configure here.
There was a problem hiding this comment.
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.
|
On |
Tobiadefami
left a comment
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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).
| 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() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
…ages-outside-interpreter
…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>
…ages-outside-interpreter
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>
There was a problem hiding this comment.
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).
…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>
|
Fixed in 32dcc09: flushing the pending transformations now clears the range caches, so |
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
left a comment
There was a problem hiding this comment.
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.
| - 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) |
There was a problem hiding this comment.
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?
…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>
|
On the |
Tobiadefami
left a comment
There was a problem hiding this comment.
Both earlier points are fixed, thanks. Two new ones in the stamp cache and the change list, plus a description fix.
| 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) | ||
| } |
There was a problem hiding this comment.
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.stampedThe 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) | ||
| } |
There was a problem hiding this comment.
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.
| 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, | ||
| ) { | ||
| } |
There was a problem hiding this comment.
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.
… fix-1762 # Conflicts: # CHANGELOG.md
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 Report❌ Patch coverage is
Additional details and impacted files@@ 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
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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).


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.
src/interpreter/still had no message.hyperformula/src/Cell.ts:CellErrorgainsoriginFunction,argumentIndex,propagated,originAddressandoriginAddressVersion, each set by a first-wins method that returns a new instance.hyperformula/src/interpreter/Interpreter.ts:evaluateAststampsoriginFunctiononce per AST node, and an error read from another cell no longer gets the reading cell as its root.hyperformula/src/DependencyGraph/DependencyGraph.ts:getCellValuemarks 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.forceApplyPostponedTransformationsmoves the addresses of the errors cached in formula vertices, including array results, to the current version.hyperformula/src/Operations.ts: the change list fromsetCellContentscarries a typed or unparsable error with the addressgetCellValuereports for it.hyperformula/src/dependencyTransformers/CleanOutOfScopeDependenciesTransformer.ts: a pasted reference that falls off the sheet reportsErrorMessage.OutOfSheet; the baseTransformerkeepsReferenceRemovedfor removed rows and columns.originFunctionfor an operator is the operator as written (+,-,*,/,^,&,%,=,<>,<,>,<=,>=).Evaluator.ts(2#CYCLE!),DependencyGraph.ts(1) andFormulaVertex.ts(1): each error gets anErrorMessageconstant. The lint rule from HF-131 (1/7): every interpreter cell error carries a message #1761 now covers all ofsrc/.hyperformula/test/_setupFiles/matchers/cellErrorComparison.ts: the Jest and JasminetoEqualErrormatchers 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.develop)A1: =1+,B1: =A1B1addressSheet1!B1Sheet1!A1A1: #REF!typed,B1: =A1B1addressSheet1!B1Sheet1!A1A1: #REF!typedA1addressSheet1!A1A1: #REF!typed,B1: =A1, then a row added aboveB2addressSheet1!B2Sheet1!A2A1: #VALUE!typed,B1: =A1, then 50 rows added onSheet2B1addressSheet1!B1Sheet1!A1B1: =A1,setCellContentsputs#VALUE!inA1A1change addressSheet1!A1A1: =10^308*10A1addressSheet1!A1B1: =A1copied and pasted intoA1A1message''Resulting reference is out of the sheet.A1: =B1,B1: =A1A1message''Cell is part of a circular reference.A1: =#REF!,A2: =C2, then column C removedA2message''Reference points to a row or column that was removed.originFunctionandargumentIndexstay internal here; #1764 exposes them.How did you test your changes?
feat/hf-131-error-messages-outside-interpreter, withunit/Cell.spec.tsand new cases inunit/error-address-preservation.spec.ts,unit/error-messages.spec.ts,unit/parser/parser.spec.tsandunit/parser/parser-caching.spec.ts.verifyValuesinunit/testUtils.tsaligns only theReferenceRemovedtoErrorLiteralmessage change that a save and reload makes, and compares every other field.Cell.spec.ts,error-address-preservation.spec.ts,parser.spec.tsandparser-caching.spec.tspass against this head (136 tests). The fourparser-caching.spec.tscases fail on this head without theParserWithCaching.tschange.OutOfSheet1, the operator names 7.src/Evaluator.tsfor a barenew CellError(ErrorType.CYCLE)and for an explicitundefinedmessage.develop),npm run benchmark:write-to-file, three alternating rounds, measured before the merge with the monorepodevelop: total median −0.24%. "Column ranges - add column" was slower in all three rounds, median +3.34% against a 1.91% base spread.AI assistance
Claude Code wrote the engine change in
hyperformula/src, thetoEqualErrorand 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
messageandaddressofDetailedCellErrordo.Public API changes
CellError(exported): five new optional constructor parameters and two readonly fields,originFunctionandargumentIndex. 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.addressof 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
originFunctionandargumentIndexonDetailedCellError: HF-131 (4/7): expose which function produced an error, and which argument #1764.Types of changes
Related issues
Checklist
dev-docs/pages this change affects – or none needed it.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.addresspoints 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.CellErrorgains immutable helpers (withOrigin,asPropagated,withOriginAddress, etc.) for first-wins origin tracking.DependencyGraph.getCellValuemarks cross-cell reads as propagated and snapshots address + transformation version for static-error cells;ExporterandLazilyTransformingAstService.applyTransformationsToAddressreplay sheet edits to keep that address current through row/column changes and compaction.Outside the interpreter, bare
CellErrorconstructions (parser, transformers, cycles, array bounds) now useErrorMessageconstants; ESLintno-restricted-syntaxapplies to all ofsrc/**/*.ts.ParserWithCachingdistinguishes otherwise identical#REF!nodes by message in the cache key. Jest/JasminetoEqualErrorshare one comparison module.Reviewed by Cursor Bugbot for commit deeabba. Bugbot is set up for automated code reviews on this repo. Configure here.