Skip to content

Commit

Permalink
Propagate Error ASAP instead of ignoring it
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach committed Dec 5, 2024
1 parent 1c2d007 commit 49c628e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# Next Next Release

#### Enso Language & Runtime

- [Propagate Error ASAP instead of ignoring it][11777].

[11777]: https://github.com/enso-org/enso/pull/11777

# Next Release

#### Enso IDE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.enso.common.MethodNames;
import org.enso.test.utils.ContextUtils;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.PolyglotException;
import org.graalvm.polyglot.Value;
import org.junit.AfterClass;
import org.junit.BeforeClass;
Expand Down Expand Up @@ -59,9 +60,13 @@ public void noErrorReturnValue() {
@Test
public void propagateErrorImmediatelly() {
var value = suppressError.execute(true, 42);
assertTrue("It is a number", value.isNumber());
assertFalse("Not an error", value.isException());
assertEquals(42, value.asInt());
assertFalse("It is not a number", value.isNumber());
assertTrue("It is an error", value.isException());
try {
throw value.throwException();
} catch (PolyglotException ex) {
assertEquals("Yielding an error", ex.getMessage());
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import com.oracle.truffle.api.source.SourceSection;
import java.util.Set;
import org.enso.interpreter.node.ExpressionNode;
import org.enso.interpreter.runtime.EnsoContext;
import org.enso.interpreter.runtime.error.DataflowError;

/**
* This node defines the body of a function for execution, as well as the protocol for executing the
Expand Down Expand Up @@ -55,8 +57,15 @@ public static BlockNode buildSilent(ExpressionNode[] expressions, ExpressionNode
@Override
@ExplodeLoop
public Object executeGeneric(VirtualFrame frame) {
var ctx = EnsoContext.get(this);
var nothing = ctx.getBuiltins().nothing();
for (ExpressionNode statement : statements) {
statement.executeGeneric(frame);
var result = statement.executeGeneric(frame);
if (result != nothing) {
if (result instanceof DataflowError err) {
return err;
}
}
}
return returnExpr.executeGeneric(frame);
}
Expand Down

0 comments on commit 49c628e

Please sign in to comment.