Skip to content

Commit

Permalink
fix: handle errors thrown in await catch attrs
Browse files Browse the repository at this point in the history
  • Loading branch information
rturnq authored and DylanPiercey committed Aug 4, 2023
1 parent 59dd026 commit 4286236
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/gold-timers-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"marko": patch
---

Handle errors thrown in await catch attribute
6 changes: 5 additions & 1 deletion packages/marko/src/core-tags/core/await/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,11 @@ function renderContents(err, data, input, out) {
if (err) {
if (input.catch) {
if (errorRenderer) {
errorRenderer(out, err);
try {
errorRenderer(out, err);
} catch (err2) {
out.error(err2);
}
}
} else {
out.error(err);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
BEFORE
<await(Promise.reject(new Error("Something went wrong!")))>
<@then|testData|>Success!</@then>
<@catch|err|>
$ throw err
</@catch>
</await>
AFTER
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var expect = require("chai").expect;

exports.templateData = {};

exports.skip_vdom = "VDOM does not support async components";

exports.checkError = function (e) {
var message = e.toString();
expect(message).to.contain("Something went wrong");
};

0 comments on commit 4286236

Please sign in to comment.