aboutsummaryrefslogtreecommitdiff
path: root/src/client/util/Scripting.ts
diff options
context:
space:
mode:
authorkimdahey <claire_kim1@brown.edu>2019-09-21 15:43:22 -0400
committerkimdahey <claire_kim1@brown.edu>2019-09-21 15:43:22 -0400
commit0b0789816e8a996b32d92e305da84b5922a49f40 (patch)
treee0a5ae13305c3f4d20413c5930f8281741fade98 /src/client/util/Scripting.ts
parentf520d5a821b515e0c216f055e93f0549bd6733a9 (diff)
parent1d5dc3eb4095cea017412de9519b8eaee979c16c (diff)
merge conflicts
Diffstat (limited to 'src/client/util/Scripting.ts')
-rw-r--r--src/client/util/Scripting.ts8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/client/util/Scripting.ts b/src/client/util/Scripting.ts
index 1d0916ac0..ff4451824 100644
--- a/src/client/util/Scripting.ts
+++ b/src/client/util/Scripting.ts
@@ -19,6 +19,7 @@ export interface ScriptSucccess {
export interface ScriptError {
success: false;
error: any;
+ result: any;
}
export type ScriptResult = ScriptSucccess | ScriptError;
@@ -27,7 +28,7 @@ export interface CompiledScript {
readonly compiled: true;
readonly originalScript: string;
readonly options: Readonly<ScriptOptions>;
- run(args?: { [name: string]: any }): ScriptResult;
+ run(args?: { [name: string]: any }, onError?: (res: any) => void, errorVal?: any): ScriptResult;
}
export interface CompileError {
@@ -100,7 +101,7 @@ function Run(script: string | undefined, customParams: string[], diagnostics: an
// let params: any[] = [Docs, ...fieldTypes];
let compiledFunction = new Function(...paramNames, `return ${script}`);
let { capturedVariables = {} } = options;
- let run = (args: { [name: string]: any } = {}): ScriptResult => {
+ let run = (args: { [name: string]: any } = {}, onError?: (e: any) => void, errorVal?: any): ScriptResult => {
let argsArray: any[] = [];
for (let name of customParams) {
if (name === "this") {
@@ -127,7 +128,8 @@ function Run(script: string | undefined, customParams: string[], diagnostics: an
if (batch) {
batch.end();
}
- return { success: false, error };
+ onError && onError(error);
+ return { success: false, error, result: errorVal };
}
};
return { compiled: true, run, originalScript, options };