fix(basic.gblib): Improving error handling in BASIC.
This commit is contained in:
parent
2fc264ab24
commit
2a199c39a3
2 changed files with 20 additions and 1 deletions
|
@ -697,15 +697,34 @@ 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);
|
||||
|
@ -713,7 +732,6 @@ export class GBVMService extends GBService {
|
|||
} catch (error) {
|
||||
GBLog.error(`BASIC ERROR: ${error.message} ${error.stack}`);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Reference in a new issue