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

fix: Correct error message when async != true #460

Merged
merged 1 commit into from Oct 19, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/ejs.js
Expand Up @@ -658,9 +658,9 @@ Template.prototype = {
e.message += ' while compiling ejs\n\n';
e.message += 'If the above error is not helpful, you may want to try EJS-Lint:\n';
e.message += 'https://github.com/RyanZim/EJS-Lint';
if (!e.async) {
if (!opts.async) {
e.message += '\n';
e.message += 'Or, if you meant to create an async function, pass async: true as an option.';
e.message += 'Or, if you meant to create an async function, pass `async: true` as an option.';
}
}
throw e;
Expand Down
26 changes: 26 additions & 0 deletions test/ejs.js
Expand Up @@ -183,6 +183,32 @@ suite('ejs.compile(str, options)', function () {
done();
});
});

test('Non-async error message mentions `async: true`', function (done) {
try {
eval('(async function() {})');
} catch (e) {
if (e instanceof SyntaxError) {
done();
return;
} else {
throw e;
}
}

try {
ejs.compile('<%= await "Hi" %>');
}
catch (err) {
if (err instanceof SyntaxError) {
assert.ok(err.message.indexOf('async: true') > -1);
return done();
} else {
throw err;
}
}
throw new Error('no error reported when there should be');
});
});

suite('client mode', function () {
Expand Down