Skip to content

Commit

Permalink
Set Correct Payload for Dataflow Errors (#1484)
Browse files Browse the repository at this point in the history
Set DataflowError payload for dataflow error updates.
  • Loading branch information
4e6 authored and iamrecursion committed Feb 23, 2021
1 parent 152873d commit e1fcd47
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import org.enso.interpreter.service.error.{
import org.enso.polyglot.LanguageInfo
import org.enso.polyglot.runtime.Runtime.Api
import org.enso.polyglot.runtime.Runtime.Api.ContextId
import org.enso.interpreter.runtime.error.PanicSentinel
import org.enso.interpreter.runtime.error.{DataflowError, PanicSentinel}

import scala.jdk.OptionConverters._

Expand Down Expand Up @@ -331,6 +331,10 @@ trait ProgramExecutionSupport {
sentinel.getMessage,
ErrorResolver.getStackTrace(sentinel).flatMap(_.expressionId)
)
case error: DataflowError =>
Api.ExpressionUpdate.Payload.DataflowError(
ErrorResolver.getStackTrace(error).flatMap(_.expressionId)
)
case _ =>
Api.ExpressionUpdate.Payload.Value()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,26 @@ class ExpressionErrorsTest
)
context.receive(6) should contain theSameElementsAs Seq(
Api.Response(requestId, Api.PushContextResponse(contextId)),
TestMessages.update(contextId, xId, Constants.ERROR),
TestMessages.update(contextId, fooBodyId, Constants.ERROR),
TestMessages.update(contextId, yId, Constants.ERROR),
TestMessages.update(contextId, mainResId, Constants.ERROR),
TestMessages.error(
contextId,
xId,
Api.ExpressionUpdate.Payload.DataflowError(Seq())
),
TestMessages.error(
contextId,
fooBodyId,
Api.ExpressionUpdate.Payload.DataflowError(Seq())
),
TestMessages.error(
contextId,
yId,
Api.ExpressionUpdate.Payload.DataflowError(Seq())
),
TestMessages.error(
contextId,
mainResId,
Api.ExpressionUpdate.Payload.DataflowError(Seq())
),
context.executionComplete(contextId)
)
}
Expand Down Expand Up @@ -543,7 +559,11 @@ class ExpressionErrorsTest
)
)
),
TestMessages.update(contextId, xId, Constants.ERROR),
TestMessages.error(
contextId,
xId,
Api.ExpressionUpdate.Payload.DataflowError(Seq())
),
TestMessages.update(contextId, yId, Constants.INTEGER),
TestMessages.update(contextId, mainResId, Constants.NOTHING),
context.executionComplete(contextId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.enso.interpreter.test.instrument

import java.util.UUID

import org.enso.interpreter.runtime.`type`.Constants
import org.enso.polyglot.runtime.Runtime.Api

/** Helper methods for creating test messages. */
Expand Down Expand Up @@ -109,4 +110,105 @@ object TestMessages {
)
)
)

/** Create an error update response.
*
* @param contextId an identifier of the context
* @param expressionId an identifier of the expression
* @param payload the error payload
* @return the expression update response
*/
def error(
contextId: UUID,
expressionId: UUID,
payload: Api.ExpressionUpdate.Payload
): Api.Response =
error(contextId, expressionId, Constants.ERROR, payload)

/** Create an error update response.
*
* @param contextId an identifier of the context
* @param expressionId an identifier of the expression
* @param expressionType a type of the expression
* @param payload the error payload
* @return the expression update response
*/
def error(
contextId: UUID,
expressionId: UUID,
expressionType: String,
payload: Api.ExpressionUpdate.Payload
): Api.Response =
errorBuilder(
contextId,
expressionId,
Some(expressionType),
None,
false,
payload
)

/** Create an error update response.
*
* @param contextId an identifier of the context
* @param expressionId an identifier of the expression
* @param expressionType a type of the expression
* @param methodPointer a pointer to the method definition
* @param fromCache whether or not the value for this expression came
* from the cache
* @param payload the error payload
* @return the expression update response
*/
def error(
contextId: UUID,
expressionId: UUID,
expressionType: String,
methodPointer: Api.MethodPointer,
fromCache: Boolean,
payload: Api.ExpressionUpdate.Payload
): Api.Response =
errorBuilder(
contextId,
expressionId,
Some(expressionType),
Some(methodPointer),
fromCache,
payload
)

/** Create an error update response.
*
* @param contextId an identifier of the context
* @param expressionId an identifier of the expression
* @param expressionTypeOpt a type of the expression
* @param methodPointerOpt a pointer to the method definition
* @param fromCache whether or not the value for this expression came
* from the cache
* @param payload the error payload
* @return the expression update response
*/
private def errorBuilder(
contextId: UUID,
expressionId: UUID,
expressionTypeOpt: Option[String],
methodPointerOpt: Option[Api.MethodPointer],
fromCache: Boolean,
payload: Api.ExpressionUpdate.Payload
): Api.Response =
Api.Response(
Api.ExpressionUpdates(
contextId,
Set(
Api.ExpressionUpdate(
expressionId,
expressionTypeOpt,
methodPointerOpt,
Vector(Api.ProfilingInfo.ExecutionTime(0)),
fromCache,
payload
)
)
)
)

}

0 comments on commit e1fcd47

Please sign in to comment.