A dataflow error with warnings reports the former (#7205)

A dataflow error resulting from calling a value with warnings now
reports only the error rather than the warning.

Closes #7141.
This commit is contained in:
Hubert Plociniczak 2023-07-05 14:18:36 +02:00 committed by GitHub
parent 2d73277238
commit a140a04689
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 90 additions and 2 deletions

View File

@ -22,7 +22,8 @@ import org.enso.interpreter.runtime.control.ThreadInterruptedException
import org.enso.interpreter.runtime.error.{
DataflowError,
PanicSentinel,
WarningsLibrary
WarningsLibrary,
WithWarnings
}
import org.enso.interpreter.service.error._
import org.enso.polyglot.LanguageInfo
@ -352,6 +353,13 @@ object ProgramExecutionSupport {
VisualizationResult.findExceptionMessage(panic),
ErrorResolver.getStackTrace(panic).flatMap(_.expressionId)
)
case warnings: WithWarnings
if warnings.getValue.isInstanceOf[DataflowError] =>
Api.ExpressionUpdate.Payload.DataflowError(
ErrorResolver
.getStackTrace(warnings.getValue.asInstanceOf[DataflowError])
.flatMap(_.expressionId)
)
case _ =>
val warnings =
Option.when(

View File

@ -1062,6 +1062,85 @@ class RuntimeErrorsTest
context.consumeOut shouldEqual List("(Error: MyError2)")
}
it should "return dataflow errors over warnings" in {
val contextId = UUID.randomUUID()
val requestId = UUID.randomUUID()
val moduleName = "Enso_Test.Test.Main"
val metadata = new Metadata
val xId = metadata.addItem(46, 9)
val yId = metadata.addItem(64, 72)
val mainResId = metadata.addItem(141, 7)
val code =
"""from Standard.Base import all
|
|main =
| x = [1, 2, 3]
| y = Warning.attach_with_stacktrace x "foo" Runtime.primitive_get_stack_trace
| y.at 10
|""".stripMargin.linesIterator.mkString("\n")
val contents = metadata.appendToCode(code)
val mainFile = context.writeMain(contents)
// create context
context.send(Api.Request(requestId, Api.CreateContextRequest(contextId)))
context.receive shouldEqual Some(
Api.Response(requestId, Api.CreateContextResponse(contextId))
)
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
// push main
context.send(
Api.Request(
requestId,
Api.PushContextRequest(
contextId,
Api.StackItem.ExplicitCall(
Api.MethodPointer(moduleName, "Enso_Test.Test.Main", "main"),
None,
Vector()
)
)
)
)
context.receiveNIgnorePendingExpressionUpdates(
6
) should contain theSameElementsAs Seq(
Api.Response(Api.BackgroundJobsStartedNotification()),
Api.Response(requestId, Api.PushContextResponse(contextId)),
TestMessages.update(contextId, xId, ConstantsGen.VECTOR),
TestMessages.update(
contextId,
yId,
ConstantsGen.VECTOR,
payload = Api.ExpressionUpdate.Payload.Value(
Some(
Api.ExpressionUpdate.Payload.Value.Warnings(1, Some("'foo'"), false)
)
)
),
TestMessages.error(
contextId,
mainResId,
methodCall = Api.MethodCall(
Api.MethodPointer(
"Standard.Base.Data.Vector",
"Standard.Base.Data.Vector.Vector",
"at"
)
),
Api.ExpressionUpdate.Payload.DataflowError(Seq(mainResId))
),
context.executionComplete(contextId)
)
context.consumeOut shouldEqual Seq()
}
it should "continue execution after thrown panics" in {
val contextId = UUID.randomUUID()
val requestId = UUID.randomUUID()

View File

@ -242,6 +242,6 @@ public final class WithWarnings implements TruffleObject {
@Override
public String toString() {
return "WithWarnings{" + value + " + " + warnings.size() + " warnings" + (limitReached ? " (warnings limit reached)}" : "}");
return "WithWarnings{" + value + " has " + warnings.size() + " warnings" + (limitReached ? " (warnings limit reached)}" : "}");
}
}

View File

@ -1,3 +1,4 @@
@Builtin_Type
type Vector a
from_array array = @Builtin_Method "Vector.from_array"
at self index = @Builtin_Method "Vector.at"