(core) Adding traceback to trigger formulas

Summary:
Traceback is available on the Creator Panel in the formula editor. It is evaluated the same way as for normal formulas.
In case when the traceback is not available, only the error name is displayed with information that traceback is not available.
Cell with an error, when edited, shows the previous valid value that was used before the error happened (or None for new rows).
Value is stored inside the RaisedException object that is stored in a cell.

Test Plan: Created tests

Reviewers: alexmojaki

Reviewed By: alexmojaki

Subscribers: alexmojaki, dsagal

Differential Revision: https://phab.getgrist.com/D3033
This commit is contained in:
Jarosław Sadziński
2021-09-25 21:14:19 +02:00
parent 048c8ee165
commit 8684c9e930
11 changed files with 244 additions and 52 deletions

View File

@@ -67,7 +67,21 @@ export class ReferenceList {
* optional details.
*/
export class RaisedException {
constructor(public name: string, public message?: string, public details?: string) {}
public name: string;
public details?: string;
public message?: string;
public user_input?: CellValue;
constructor(list: any[]) {
if (!list.length) {
throw new Error("RaisedException requires a name as first element");
}
list = [...list];
this.name = list.shift();
this.message = list.shift();
this.details = list.shift();
this.user_input = list.shift()?.u;
}
/**
* This is designed to look somewhat similar to Excel, e.g. #VALUE or #DIV/0!"
@@ -195,7 +209,7 @@ export function decodeObject(value: CellValue): unknown {
switch (code) {
case 'D': return GristDateTime.fromGristValue(args[0], String(args[1]));
case 'd': return GristDate.fromGristValue(args[0]);
case 'E': return new RaisedException(args[0], args[1], args[2]);
case 'E': return new RaisedException(args);
case 'L': return (args as CellValue[]).map(decodeObject);
case 'O': return mapValues(args[0] as {[key: string]: CellValue}, decodeObject, {sort: true});
case 'P': return new PendingValue();