Skip to content

Commit 49c628e

Browse files
Propagate Error ASAP instead of ignoring it
1 parent 1c2d007 commit 49c628e

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# Next Next Release
2+
3+
#### Enso Language & Runtime
4+
5+
- [Propagate Error ASAP instead of ignoring it][11777].
6+
7+
[11777]: https://github.com/enso-org/enso/pull/11777
8+
19
# Next Release
210

311
#### Enso IDE

engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/semantic/DataflowErrorPropagationTest.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.enso.common.MethodNames;
88
import org.enso.test.utils.ContextUtils;
99
import org.graalvm.polyglot.Context;
10+
import org.graalvm.polyglot.PolyglotException;
1011
import org.graalvm.polyglot.Value;
1112
import org.junit.AfterClass;
1213
import org.junit.BeforeClass;
@@ -59,9 +60,13 @@ public void noErrorReturnValue() {
5960
@Test
6061
public void propagateErrorImmediatelly() {
6162
var value = suppressError.execute(true, 42);
62-
assertTrue("It is a number", value.isNumber());
63-
assertFalse("Not an error", value.isException());
64-
assertEquals(42, value.asInt());
63+
assertFalse("It is not a number", value.isNumber());
64+
assertTrue("It is an error", value.isException());
65+
try {
66+
throw value.throwException();
67+
} catch (PolyglotException ex) {
68+
assertEquals("Yielding an error", ex.getMessage());
69+
}
6570
}
6671

6772
@Test

engine/runtime/src/main/java/org/enso/interpreter/node/callable/function/BlockNode.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import com.oracle.truffle.api.source.SourceSection;
1010
import java.util.Set;
1111
import org.enso.interpreter.node.ExpressionNode;
12+
import org.enso.interpreter.runtime.EnsoContext;
13+
import org.enso.interpreter.runtime.error.DataflowError;
1214

1315
/**
1416
* This node defines the body of a function for execution, as well as the protocol for executing the
@@ -55,8 +57,15 @@ public static BlockNode buildSilent(ExpressionNode[] expressions, ExpressionNode
5557
@Override
5658
@ExplodeLoop
5759
public Object executeGeneric(VirtualFrame frame) {
60+
var ctx = EnsoContext.get(this);
61+
var nothing = ctx.getBuiltins().nothing();
5862
for (ExpressionNode statement : statements) {
59-
statement.executeGeneric(frame);
63+
var result = statement.executeGeneric(frame);
64+
if (result != nothing) {
65+
if (result instanceof DataflowError err) {
66+
return err;
67+
}
68+
}
6069
}
6170
return returnExpr.executeGeneric(frame);
6271
}

0 commit comments

Comments
 (0)