diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f99e4c2e..b277ff455 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Fixed the `EDATE` function returning the 28th of February instead of the 29th when the shifted date falls in February of a leap year (e.g. `=EDATE(DATE(2028, 1, 31), 1)` now returns `2028-02-29` instead of `2028-02-28`). [#1781](https://github.com/handsontable/hyperformula/pull/1781) - Fixed a cell holding a static error value, such as a rejected formula or a typed-in error, being reported under the address of the cell that read it first instead of its own address. [#1547](https://github.com/handsontable/hyperformula/issues/1547) - Fixed `#SPILL!` errors reporting no address; their `address` is now the cell whose array result could not spill. [#1547](https://github.com/handsontable/hyperformula/issues/1547) +- Fixed reading a formula cell's value before it was computed throwing a plain `Error` that did not say which cell it was; it now throws `CellValueNotComputedError`, which carries the cell's address. [#444](https://github.com/handsontable/hyperformula/issues/444) ## [3.5.0] - 2026-10-09 diff --git a/hyperformula/src/DependencyGraph/FormulaVertex.ts b/hyperformula/src/DependencyGraph/FormulaVertex.ts index fbea5f644..aff74894e 100644 --- a/hyperformula/src/DependencyGraph/FormulaVertex.ts +++ b/hyperformula/src/DependencyGraph/FormulaVertex.ts @@ -9,6 +9,7 @@ import {ArrayValue, ErroredArray, CellArray, NotComputedArray} from '../ArrayVal import {CellError, equalSimpleCellAddress, ErrorType, SimpleCellAddress} from '../Cell' import {RawCellContent} from '../CellContentParser' import {ErrorMessage} from '../error-message' +import {CellValueNotComputedError} from '../errors' import {EmptyValue, getRawValue, InternalScalarValue, InterpreterValue} from '../interpreter/InterpreterValue' import {LazilyTransformingAstService} from '../LazilyTransformingAstService' import {Maybe} from '../Maybe' @@ -136,7 +137,7 @@ export class ArrayFormulaVertex extends FormulaVertex { getCellValue(): InterpreterValue { if (this.array instanceof NotComputedArray) { - throw Error('Array not computed yet.') + throw new CellValueNotComputedError(this.cellAddress) } return this.array.simpleRangeValue() } @@ -275,7 +276,7 @@ export class ScalarFormulaVertex extends FormulaVertex { if (this.cachedCellValue !== undefined) { return this.cachedCellValue } else { - throw Error('Value of the formula cell is not computed.') + throw new CellValueNotComputedError(this.cellAddress) } } diff --git a/hyperformula/src/errors.ts b/hyperformula/src/errors.ts index 16baf2b88..378f4b1a5 100644 --- a/hyperformula/src/errors.ts +++ b/hyperformula/src/errors.ts @@ -61,6 +61,19 @@ export class InvalidAddressError extends Error { } } +/** + * Error thrown when a formula cell's value is read before it has been computed. + * + * Carries the address as a field, so callers can trace the cell without parsing + * it back out of the message. + * Thrown by both ScalarFormulaVertex and ArrayFormulaVertex. + */ +export class CellValueNotComputedError extends Error { + constructor(public readonly address: SimpleCellAddress) { + super(`Value of the formula cell (sheet = ${address.sheet}, row = ${address.row}, col = ${address.col}) is not computed.`) + } +} + /** * Error thrown when the given arguments are invalid */ diff --git a/hyperformula/src/index.ts b/hyperformula/src/index.ts index f48715c9f..22eccbc0b 100644 --- a/hyperformula/src/index.ts +++ b/hyperformula/src/index.ts @@ -16,6 +16,7 @@ import { DenseSparseChooseBasedOnThreshold } from './DependencyGraph/AddressMapping/ChooseAddressMappingPolicy' import { + CellValueNotComputedError, ConfigValueTooBigError, ConfigValueTooSmallError, EvaluationSuspendedError, @@ -74,6 +75,7 @@ class HyperFormulaNS extends HyperFormula { public static DetailedCellError = DetailedCellError public static ExportedCellChange = ExportedCellChange public static ExportedNamedExpressionChange = ExportedNamedExpressionChange + public static CellValueNotComputedError = CellValueNotComputedError public static ConfigValueTooBigError = ConfigValueTooBigError public static ConfigValueTooSmallError = ConfigValueTooSmallError public static EvaluationSuspendedError = EvaluationSuspendedError @@ -159,6 +161,7 @@ export { ExportedNamedExpressionChange, DetailedCellError, CellError, + CellValueNotComputedError, ConfigValueTooBigError, ConfigValueTooSmallError, EvaluationSuspendedError,