Skip to content

Commit

Permalink
fix(basic.gblib): Improving error handling in BASIC.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigorodriguez committed Jan 5, 2021
1 parent 2fc264a commit 2a199c3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
20 changes: 19 additions & 1 deletion packages/basic.gblib/services/GBVMService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -697,23 +697,41 @@ export class GBVMService extends GBService {
);
}

/**
* Executes the converted JavaScript from BASIC code inside execution context.
*/
public static async callVM(text: string, min: GBMinInstance, step: GBDialogStep, deployer: GBDeployer) {

// Creates a class DialogKeywords which is the *this* pointer
// in BASIC.

const sandbox: DialogKeywords = new DialogKeywords(min, deployer);

// Injects the .gbdialog generated code into the VM.

const context = vm.createContext(sandbox);
const code = min.sandBoxMap[text];
vm.runInContext(code, context);

// Tries to find the method related to this call.

const mainMethod = text.toLowerCase();
if (!sandbox[mainMethod]) {
GBLog.error(`BASIC: Associated '${mainMethod}' dialog not found. Verify if .gbdialog is correctly published.`);

return null;
}
sandbox[mainMethod].bind(sandbox);

// Calls the function.

let ret = null;
try {
ret = await sandbox[mainMethod](step);

} catch (error) {
GBLog.error(`BASIC ERROR: ${error.message} ${error.stack}`);
}

return ret;
}
}
1 change: 1 addition & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export class GBServer {
*/

public static run() {

GBLog.info(`The Bot Server is in STARTING mode...`);
GBServer.globals = new RootData();
GBConfigService.init();
Expand Down

0 comments on commit 2a199c3

Please sign in to comment.