Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
43ef5f5
HF-131: stop a cell adopting an error it only read
marcin-kordas-hoc Sep 7, 2026
8b9826f
HF-131: give every non-interpreter cell error a message
marcin-kordas-hoc Sep 8, 2026
128f261
HF-131: add the ESLint rule, scoped to src/interpreter/
marcin-kordas-hoc Sep 10, 2026
9c4015e
HF-131: widen the ESLint rule to all of src/
marcin-kordas-hoc Sep 10, 2026
f667a23
Merge remote-tracking branch 'pr1/feat-hf-131-error-messages' into fe…
marcin-kordas-hoc Sep 11, 2026
749044d
Merge remote-tracking branch 'pr1/tip2' into feat/hf-131-error-messag…
marcin-kordas-hoc Sep 11, 2026
e33b35f
HF-131: keep a static error's address current as rows and columns move
marcin-kordas-hoc Sep 14, 2026
82c71d6
Merge branch 'feat/hf-131-error-messages' into feat/hf-131-error-mess…
marcin-kordas-hoc Sep 14, 2026
d8cd6cf
HF-131: complete the matcher's ignore list, as the file asks
marcin-kordas-hoc Sep 14, 2026
d53bb73
docs: shorten the changelog entries, describe the CellContent.Error c…
marcin-kordas-hoc Oct 22, 2026
2129c85
Merge feat/hf-131-error-messages into feat/hf-131-error-messages-outs…
marcin-kordas-hoc Oct 22, 2026
c5feea6
Merge feat/hf-131-error-messages into feat/hf-131-error-messages-outs…
marcin-kordas-hoc Oct 23, 2026
499d0b2
Merge feat/hf-131-error-messages into feat/hf-131-error-messages-outs…
marcin-kordas-hoc Nov 4, 2026
4db2b54
Keep error nodes with different messages apart in the AST cache
marcin-kordas-hoc Nov 5, 2026
5f519ca
Merge branch 'feat/hf-131-error-messages' into feat/hf-131-error-mess…
marcin-kordas-hoc Nov 12, 2026
deeabba
Report error origins consistently across change lists, compaction and…
marcin-kordas-hoc Nov 12, 2026
58cfeb5
Merge branch 'feat/hf-131-error-messages' into feat/hf-131-error-mess…
marcin-kordas-hoc Nov 17, 2026
a9893fb
Merge branch 'feat/hf-131-error-messages' into feat/hf-131-error-mess…
marcin-kordas-hoc Nov 18, 2026
653b627
Merge branch 'feat/hf-131-error-messages' into feat/hf-131-error-mess…
marcin-kordas-hoc Nov 20, 2026
91701c6
Merge branch 'feat/hf-131-error-messages' into feat/hf-131-error-mess…
marcin-kordas-hoc Nov 22, 2026
acc1b29
Merge branch 'feat/hf-131-error-messages' into feat/hf-131-error-mess…
marcin-kordas-hoc Nov 25, 2026
32dcc09
Clear the range caches when the pending transformations are flushed
marcin-kordas-hoc Nov 25, 2026
0e0c8c9
Merge branch 'feat/hf-131-error-messages' into feat/hf-131-error-mess…
marcin-kordas-hoc Nov 25, 2026
ca23e25
Make the propagated copy of an error once
marcin-kordas-hoc Nov 25, 2026
0beed80
Reuse the stamped copy of a static error while its address and versio…
marcin-kordas-hoc Nov 25, 2026
afccb1d
Reuse the stamped copy of a static error across row and column changes
marcin-kordas-hoc Nov 25, 2026
52079d6
Keep the stamp's address and version in the static-error cache
marcin-kordas-hoc Nov 26, 2026
c428b84
Merge branch 'feat/hf-131-error-messages' into feat/hf-131-error-mess…
marcin-kordas-hoc Nov 26, 2026
3ebc7dc
Remove the Breaking change entries the merge duplicated, and keep one…
marcin-kordas-hoc Nov 29, 2026
2953400
Give an error written into the formula no origin function
marcin-kordas-hoc Nov 30, 2026
36e5373
Name every error node the origin lock covers
marcin-kordas-hoc Nov 30, 2026
dba23e7
Merge remote-tracking branch 'origin/feat/hf-131-error-messages' into…
marcin-kordas-hoc Dec 3, 2026
c69f479
Move a reused static-error stamp to the current transformation version
marcin-kordas-hoc Dec 3, 2026
b297384
Keep the origin address of errors in a batch's change list across a c…
marcin-kordas-hoc Dec 3, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Changed

- Changed `XLOOKUP` with `search_mode` 2 or -2 to find more exact matches in a range that is not sorted, e.g. 3 in 5, 1, 3, 2, 4, where it returned no match before. The result on unsorted data is still not guaranteed. [#1806](https://github.com/handsontable/hyperformula/pull/1806)
- Changed the cell errors produced while evaluating a formula to carry a message describing their cause. [#1547](https://github.com/handsontable/hyperformula/issues/1547)
- 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)

### Added

Expand All @@ -24,6 +24,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

- Fixed the parser rejecting formulas with the function-name prefixes that Excel writes into `.xlsx` files (e.g. `_xlfn.XLOOKUP`), which are now ignored and left out of `getCellFormula()`. [#1655](https://github.com/handsontable/hyperformula/issues/1655)
- Fixed approximate `MATCH`, `VLOOKUP` and `HLOOKUP`, and `XLOOKUP` with `search_mode` 2 or -2, misordering text that differs in letter case or accents, e.g. `=MATCH("é", A1:A3, 1)` over a, é, f now returns `2` instead of `1`. [#1806](https://github.com/handsontable/hyperformula/pull/1806)
- Fixed `DetailedCellError.address` for a typed-in error, an unparsable formula, or an overflow such as `=10^308*10`: the cell and every formula reading it now report the error's own cell, instead of none and each reader's own address. [#1547](https://github.com/handsontable/hyperformula/issues/1547)

## [4.0.0] - 2026-12-02

Expand Down
6 changes: 4 additions & 2 deletions hyperformula/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,14 @@ module.exports = {
}
},
{
files: ['**/src/interpreter/**/*.ts'],
files: ['**/src/**/*.ts'],
rules: {
// An engine-thrown cell error must always state its cause.
// The public `CellError` constructor keeps `message` optional for custom
// functions (docs/guide/custom-functions.md); this rule enforces the
// stricter contract on our own code only.
// stricter contract on our own code only. It is a syntactic floor, not a
// proof of completeness — see the comment at CellContentParser.ts's
// `CellContent.Error` constructor for a call site it cannot catch.
'no-restricted-syntax': ['error',
{
selector: "NewExpression[callee.name='CellError'][arguments.length<2]",
Expand Down
2 changes: 2 additions & 0 deletions hyperformula/dev-docs/INTERPRETER.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

- **Coerce through `ArithmeticHelper`.** Never write ad-hoc string-to-number or value-to-boolean conversion inside a function; the coercion rules are spreadsheet semantics, not JavaScript semantics, and they are already implemented once.
- **Errors are values.** Return a `CellError` with a message from `hyperformula/src/error-message.ts`. Do not throw: a thrown error escapes the evaluation of one cell and takes the recalculation with it.
- **Read cell values through `DependencyGraph.getCellValue`.** It marks an error read from another cell as propagated, and stamps the address of a cell that holds a typed or unparsable error. Reading the address mapping directly skips both, and the reading cell is then reported as the error's origin.
- **Pass a read error on unchanged.** An error that came from an argument or another cell already names its origin; return that instance. `withOrigin` and `withArgumentIndex` keep the first value set and ignore a propagated error, so a function that only received an error never takes it over. Building a new `CellError` from a read error's type discards its origin and address.
- **Never spread a range's values into a call.** `push(...values)` and `Math.max(...values)` pass one argument per value, and a range or array of about 125,000 values (Node 24, default stack size) throws `RangeError: Maximum call stack size exceeded` out of the recalculation. Append in a loop.
- **The registry is keyed by id, not by implementation.** A custom plugin can be registered over a built-in id. Do not assume the plugin you are reading is the one that will answer for that id at run time.
- **Evaluate each argument once.** Evaluating the same argument twice doubles its cost and, when it contains a volatile function such as `RAND`, can see two different values.
Expand Down
145 changes: 143 additions & 2 deletions hyperformula/src/Cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,155 @@ export const getCellValueFormat = (cellValue: InterpreterValue): string | undefi
}
}

/**
* The propagated copy of each error, made once. Every read of a cell that holds an error goes through
* `asPropagated`, and the evaluator reports a cell as changed when its new value is a different
* object, so a fresh copy per read would report an unchanged error as a change. A `WeakMap` rather
* than a field keeps the error's own properties, which equality checks compare, unchanged.
*/
const propagatedCopies = new WeakMap<CellError, CellError>()

/** The origin-locked copy of each error, made once, for the same reason as `propagatedCopies`. */
const originLockedCopies = new WeakMap<CellError, CellError>()

export class CellError {
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,
) {
}
Comment thread
Tobiadefami marked this conversation as resolved.
Resolved
Comment on lines 164 to 179

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.


/**
* Names the function or operator that produced this error.
*
* First occurrence wins, so an outer function that merely received the error back does not
* claim it: `=SUM(SQRT(-1))` keeps `SQRT`. Two kinds of error never acquire an origin they did
* not already have:
* - a propagated error, one read out of another cell rather than produced here;
* - an origin-locked error, one written into the formula itself (see {@link asOriginLocked}), so
* `=SUM(#N/A)`, `=#DIV/0!+1` and `=SUM(#REF!)` left by a removed column name no function.
*
* @param {string} functionName - the function or operator helper that produced the error
*
* @internal
*/
public withOrigin(functionName: string): CellError {
if (this.propagated || this.originLocked || this.originFunction !== undefined) {
return this
}
return new CellError(this.type, this.message, this.root, functionName, this.argumentIndex, this.propagated, this.originAddress, this.originAddressVersion, this.originLocked)
}

/**
* Records which argument of the origin function was rejected. First occurrence wins, and a
* propagated error never acquires one: the reading function's own argument slot is not the
* offending argument.
*
* @param {number} index - zero-based index of the offending argument
*
* @internal
*/
public withArgumentIndex(index: number): CellError {
if (this.propagated || this.argumentIndex !== undefined) {
return this
}
return new CellError(this.type, this.message, this.root, this.originFunction, index, this.propagated, this.originAddress, this.originAddressVersion, this.originLocked)
}

/**
* Marks this error as having all the origin it will ever have, so `withOrigin` leaves it alone.
*
* The interpreter applies it to the error an `ERROR` or `ERROR_WITH_RAW_INPUT` node evaluates
* to: an error value typed into the formula, the `#REF!` a reference turns into once its row or
* column is removed, or the error the parser puts in place of a reference it cannot resolve or
* one beyond the sheet size limits. A reference to a removed sheet stays a reference and is not
* such a node. No function or operator produced such an error, so the first one
* that receives it must not claim it. Unlike `asPropagated`, it leaves the root vertex to be
* attached as usual, so the error is still reported at the cell whose formula contains it.
*
* @internal
*/
public asOriginLocked(): CellError {
if (this.originLocked) {
return this
}
let copy = originLockedCopies.get(this)
if (copy === undefined) {
copy = new CellError(this.type, this.message, this.root, this.originFunction, this.argumentIndex, this.propagated, this.originAddress, this.originAddressVersion, true)
originLockedCopies.set(this, copy)
}
return copy
}

/**
* Marks this error as read from another cell rather than produced by the current evaluation.
*
* This is what stops a cell from adopting an error it only read: `wrapperForRootVertex` in
* `Interpreter.ts` does not attach the evaluating cell as the root of a propagated error, so the
* reported address stays the one where the error actually appeared.
*
* @internal
*/
public asPropagated(): CellError {
if (this.propagated) {
return this
}
let copy = propagatedCopies.get(this)
if (copy === undefined) {
copy = new CellError(this.type, this.message, this.root, this.originFunction, this.argumentIndex, true, this.originAddress, this.originAddressVersion, this.originLocked)
propagatedCopies.set(this, copy)
}
return copy
}

/**
* Records the address an otherwise rootless error appeared at, and the moment it was recorded.
*
* For vertices that hold a static error rather than computing one (a parse error, or an error
* value the user typed), there is no `FormulaVertex` to serve as a lazily-resolved `root`, so
* the address has to be recorded on the value itself. A recorded address is a snapshot and does
* go stale: the cell that read it caches this instance, and a later row or column change that
* merely shifts that cell does not recompute it. The `version` is what makes the snapshot
* repairable — it names the point in `LazilyTransformingAstService`'s history the address was
* true at, so `Exporter` can replay the intervening transformations over it and report where the
* origin sits now. See {@link LazilyTransformingAstService.applyTransformationsToAddress}.
*
* @param {SimpleCellAddress} address - the address the error was read from
* @param {number} version - the transformation version that address was current at
*
* @internal
*/
public withOriginAddress(address: SimpleCellAddress, version: number): CellError {
if (this.originAddress !== undefined) {
return this
}
return new CellError(this.type, this.message, this.root, this.originFunction, this.argumentIndex, this.propagated, address, version, this.originLocked)
}

/**
* Replaces the recorded origin address with the same origin expressed at a later transformation
* version. Used before old transformations are discarded, so that a cached copy of a static
* error can still be moved by the transformations that follow.
*
* @param {SimpleCellAddress} address - the origin address as it is at `version`
* @param {number} version - the transformation version that address is current at
* @internal
*/
public withRebasedOriginAddress(address: SimpleCellAddress, version: number): CellError {
return new CellError(this.type, this.message, this.root, this.originFunction, this.argumentIndex, this.propagated, address, version, this.originLocked)
}

/**
* Returns a CellError with a given message.
* @param {string} detailedMessage - message to be displayed
Expand All @@ -167,7 +308,7 @@ export class CellError {

public attachRootVertex(vertex: FormulaVertex): CellError {
if (this.root === undefined) {
return new CellError(this.type, this.message, vertex)
return new CellError(this.type, this.message, vertex, this.originFunction, this.argumentIndex, this.propagated, this.originAddress, this.originAddressVersion, this.originLocked)
} else {
return this
}
Expand Down
9 changes: 9 additions & 0 deletions hyperformula/src/CellContentParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ export namespace CellContent {
export class Error {
public readonly value: CellError

// `message` stays optional here on purpose. This constructor's only
// no-message caller is the `errorMapping` lookup below (a user typing e.g.
// `#REF!` literally into a cell) — the engine has no cause to state beyond
// "the user wrote this", so leaving it unset is honest, not an oversight.
// This is also the concrete case the cell-error ESLint rule (.eslintrc.js) cannot
// catch: the call `new CellError(errorType, message)` is syntactically a
// two-argument construction and passes the rule cleanly even when the
// caller passes no message, because the rule only inspects this call site,
// not who calls it.
constructor(errorType: ErrorType, message?: string) {
this.value = new CellError(errorType, message)
}
Expand Down
15 changes: 14 additions & 1 deletion hyperformula/src/ContentChanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Copyright (c) Handsoncode sp. z o.o. All rights reserved.
*/

import {addressKey, SimpleCellAddress} from './Cell'
import {addressKey, CellError, SimpleCellAddress} from './Cell'
import {InterpreterValue} from './interpreter/InterpreterValue'
import {SimpleRangeValue} from './SimpleRangeValue'

Expand Down Expand Up @@ -58,6 +58,19 @@ export class ContentChanges {
return this.changes.size === 0
}

/**
* Replaces each error value in the list with the result of `fn`.
*
* @param {function} fn - maps an error to the error the change should carry instead
*/
public mapErrorValues(fn: (error: CellError) => CellError): void {
for (const change of this.changes.values()) {
if (change.value instanceof CellError) {
change.value = fn(change.value)
}
}
}

private add(address: SimpleCellAddress, change: CellValueChange) {
const value = change.value
if (value instanceof SimpleRangeValue) {
Expand Down
Loading
Loading