Skip to content
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

Include error message when error raised by object macro #341

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/brain.js
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,7 @@ class Brain {
if (error != undefined) {
self.warn(error);
}
output = "[ERR: Error raised by object macro]";
output = `[ERR: Error raised by object macro: ${error.message}]`;
}
} else {
output = "[ERR: No Object Handler]";
Expand Down
27 changes: 26 additions & 1 deletion test/test-objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ exports.test_await_macro = async function(test) {
// Test if we have async support in our local JS environment, or else skip
// this test.
try {
eval("(asyc function() {})");
eval("(async function() {})");
} catch(e) {
console.log("skip test_await_macro: local JS environment doesn't support async/await");
return test.done();
Expand Down Expand Up @@ -421,3 +421,28 @@ exports.test_await_macro = async function(test) {
await bot.reply("test async", "Ok: Alice, you have called this macro 3 times.");
test.done();
};

exports.test_error_in_await_macro = async function(test) {
// In RiveScript 2.0.0, macros parsed from RiveScript code are loaded as
// async functions, allowing them to use the await keyword.

// Test if we have async support in our local JS environment, or else skip
// this test.
try {
eval("(async function() {})");
} catch(e) {
console.log("skip test_error_in_await_macro: local JS environment doesn't support async/await");
return test.done();
}

var bot = new TestCase(test, `
> object awaitable javascript
throw new Error('TestError');
< object

+ test async
- Ok: <call>awaitable</call>
`);
await bot.reply("test async", "Ok: [ERR: Error raised by object macro: TestError]");
test.done();
};