Repository navigation
HF-131 (2/7): the origin/propagation mechanism, plus the same guarantee outside the interpreter #1762
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
marcin-kordas-hoc
wants to merge
34
commits into
feat/hf-131-error-messages
Choose a base branch
from
feat/hf-131-error-messages-outside-interpreter
base: feat/hf-131-error-messages
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
HF-131 (2/7): the origin/propagation mechanism, plus the same guarantee outside the interpreter #1762
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 8b9826f
HF-131: give every non-interpreter cell error a message
marcin-kordas-hoc 128f261
HF-131: add the ESLint rule, scoped to src/interpreter/
marcin-kordas-hoc 9c4015e
HF-131: widen the ESLint rule to all of src/
marcin-kordas-hoc f667a23
Merge remote-tracking branch 'pr1/feat-hf-131-error-messages' into fe…
marcin-kordas-hoc 749044d
Merge remote-tracking branch 'pr1/tip2' into feat/hf-131-error-messag…
marcin-kordas-hoc e33b35f
HF-131: keep a static error's address current as rows and columns move
marcin-kordas-hoc 82c71d6
Merge branch 'feat/hf-131-error-messages' into feat/hf-131-error-mess…
marcin-kordas-hoc d8cd6cf
HF-131: complete the matcher's ignore list, as the file asks
marcin-kordas-hoc d53bb73
docs: shorten the changelog entries, describe the CellContent.Error c…
marcin-kordas-hoc 2129c85
Merge feat/hf-131-error-messages into feat/hf-131-error-messages-outs…
marcin-kordas-hoc c5feea6
Merge feat/hf-131-error-messages into feat/hf-131-error-messages-outs…
marcin-kordas-hoc 499d0b2
Merge feat/hf-131-error-messages into feat/hf-131-error-messages-outs…
marcin-kordas-hoc 4db2b54
Keep error nodes with different messages apart in the AST cache
marcin-kordas-hoc 5f519ca
Merge branch 'feat/hf-131-error-messages' into feat/hf-131-error-mess…
marcin-kordas-hoc deeabba
Report error origins consistently across change lists, compaction and…
marcin-kordas-hoc 58cfeb5
Merge branch 'feat/hf-131-error-messages' into feat/hf-131-error-mess…
marcin-kordas-hoc a9893fb
Merge branch 'feat/hf-131-error-messages' into feat/hf-131-error-mess…
marcin-kordas-hoc 653b627
Merge branch 'feat/hf-131-error-messages' into feat/hf-131-error-mess…
marcin-kordas-hoc 91701c6
Merge branch 'feat/hf-131-error-messages' into feat/hf-131-error-mess…
marcin-kordas-hoc acc1b29
Merge branch 'feat/hf-131-error-messages' into feat/hf-131-error-mess…
marcin-kordas-hoc 32dcc09
Clear the range caches when the pending transformations are flushed
marcin-kordas-hoc 0e0c8c9
Merge branch 'feat/hf-131-error-messages' into feat/hf-131-error-mess…
marcin-kordas-hoc ca23e25
Make the propagated copy of an error once
marcin-kordas-hoc 0beed80
Reuse the stamped copy of a static error while its address and versio…
marcin-kordas-hoc afccb1d
Reuse the stamped copy of a static error across row and column changes
marcin-kordas-hoc 52079d6
Keep the stamp's address and version in the static-error cache
marcin-kordas-hoc c428b84
Merge branch 'feat/hf-131-error-messages' into feat/hf-131-error-mess…
marcin-kordas-hoc 3ebc7dc
Remove the Breaking change entries the merge duplicated, and keep one…
marcin-kordas-hoc 2953400
Give an error written into the formula no origin function
marcin-kordas-hoc 36e5373
Name every error node the origin lock covers
marcin-kordas-hoc dba23e7
Merge remote-tracking branch 'origin/feat/hf-131-error-messages' into…
marcin-kordas-hoc c69f479
Move a reused static-error stamp to the current transformation version
marcin-kordas-hoc b297384
Keep the origin address of errors in a batch's change list across a c…
marcin-kordas-hoc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 on lines
164
to
179
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
|
||
| /** | ||
| * 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 | ||
|
|
@@ -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 | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.