Skip to content

Commit 7f9e362

Browse files
ford-prefectnatefaubion
authored andcommitted
Try to recover from effectful code that is annotated as pure (#173)
This puts a try-catch around the bind step in order to try to catch code that is not expected to have effects but does (by throwing). While this is clearly a programming error, it is certainly not implausible that effects creep into FFI code inadvertently for Aff users. This allows us to be defensive in that case and recover, rather than have all asynchronous options quitely not work after. The addition of the try-catch does not seem to have a performance impact (tested on Node v10.15.3). With and without this change, `pulp test` takes ~4.8s to run. There is a discussion around this on #172.
1 parent 390857f commit 7f9e362

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/Effect/Aff.js

+12-6
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,18 @@ var Aff = function () {
274274
switch (status) {
275275
case STEP_BIND:
276276
status = CONTINUE;
277-
step = bhead(step);
278-
if (btail === null) {
279-
bhead = null;
280-
} else {
281-
bhead = btail._1;
282-
btail = btail._2;
277+
try {
278+
step = bhead(step);
279+
if (btail === null) {
280+
bhead = null;
281+
} else {
282+
bhead = btail._1;
283+
btail = btail._2;
284+
}
285+
} catch (e) {
286+
status = RETURN;
287+
fail = util.left(e);
288+
step = null;
283289
}
284290
break;
285291

0 commit comments

Comments
 (0)