Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix problems related to error visualisation evaluation #3193

Merged
merged 68 commits into from
Dec 21, 2021
Merged
Show file tree
Hide file tree
Changes from 67 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
92d9157
DEBUG mark place in Engine sending the error
akavel Dec 15, 2021
e8a2285
rough dump of the real notification to dev console
akavel Dec 15, 2021
158ac89
DEBUG try dumping visualisation diagnostic path
akavel Dec 15, 2021
a5c282f
quick fix: change string delimiters
akavel Dec 15, 2021
d6e3e39
DEBUG try to see when error preprocessor is run
akavel Dec 15, 2021
4b28ac6
DEBUG try to see when preprocessor is changed
akavel Dec 15, 2021
bafdce1
Revert "DEBUG try to see when error preprocessor is run"
akavel Dec 15, 2021
7c415dd
Revert "DEBUG try to see when preprocessor is changed"
akavel Dec 15, 2021
2adf602
DEBUG comment-out some no longer needed debugs
akavel Dec 16, 2021
98b4c06
DEBUG around executionService.callFunction(visualisation.callbck,expr…
akavel Dec 16, 2021
da09bff
DEBUG more Scala debugging
akavel Dec 16, 2021
649de08
DEBUG problematic snippet, having trouble with PanicSentinel argument
akavel Dec 16, 2021
5962d9d
first try of Builtins.Panic.Recover
akavel Dec 16, 2021
4a0e66d
rethrow
akavel Dec 16, 2021
797db5d
bring back message.to_json.to_text
akavel Dec 16, 2021
6a708c2
cleanup preprocessor
akavel Dec 16, 2021
7010c02
CLEANUP some scala DEBUGs
akavel Dec 16, 2021
e562aa5
WIP writing visualisation test in Engine
akavel Dec 16, 2021
3ee3cdc
WIP writing visualisation test in Engine
akavel Dec 16, 2021
f39260d
WIP change to fixed code in test
akavel Dec 16, 2021
1b6f18a
sketch of a simpler test
akavel Dec 16, 2021
e58fa8d
fix scope
akavel Dec 16, 2021
a45a2fa
import InterpreterException
akavel Dec 16, 2021
613e8d6
WIP temporarily use "Test" package to make it work
akavel Dec 16, 2021
20d4715
WIP trying to capture a panic as value in test
akavel Dec 16, 2021
3edb1f4
WIP trying to capture a panic as value in test cont.d
akavel Dec 16, 2021
9b67755
WIP
akavel Dec 17, 2021
ba18f9f
BACKOFF PanicSentinel handling in IDE, reportedly that case is a bug …
akavel Dec 17, 2021
3163b45
BACKOFF test attempts in Scala for now
akavel Dec 17, 2021
8957626
more fields in VEF msg
akavel Dec 17, 2021
e302edb
more detail in visualisation error
akavel Dec 17, 2021
95e3784
extract preprocessor code to a file for reuse in Scala
akavel Dec 17, 2021
e408f1b
WIP trying to write scala test for preprocessor
akavel Dec 17, 2021
8987f0a
 try making the test work
akavel Dec 17, 2021
e139470
Merge remote-tracking branch 'origin/develop' into wip/akavel/unknown…
akavel Dec 17, 2021
c28f85c
DEBUG print out values around callFunction again
akavel Dec 20, 2021
7444e45
DEBUG simplify test to pass easier locally
akavel Dec 20, 2021
5695b98
WIP try iterating from working preprocessor to the IDE one step-by-step
akavel Dec 20, 2021
0ce1129
WIP catch does not work, but .to_display_text does
akavel Dec 20, 2021
776881d
WIP changing the module seems to break; commented out for now
akavel Dec 20, 2021
0517859
WIP multiline lambda in catch_primitive works
akavel Dec 20, 2021
919bd6c
WIP "Method `to_json` of Text could not be found."
akavel Dec 20, 2021
32b80c8
WIP "Fatal: Unhandled entity in translateExpression =...import..."
akavel Dec 20, 2021
2e5917f
Revert "WIP "Fatal: Unhandled entity in translateExpression =...impor…
akavel Dec 20, 2021
8016df2
WIP changing the module of just the *visualisation preprocessor* seem…
akavel Dec 20, 2021
9e686fb
WIP put module name in variable
akavel Dec 20, 2021
2893ea7
WIP strings addition works
akavel Dec 20, 2021
1145c08
WIP catch works when in module as expected
akavel Dec 20, 2021
4f226e3
original IDE snippet runs correctly when in same module as used in IDE
akavel Dec 20, 2021
b1e9f71
fix expected message to make the test pass
akavel Dec 20, 2021
5a1b5e2
CLEANUP test preprocessors
akavel Dec 20, 2021
ab3149a
Revert "DEBUG print out values around callFunction again"
akavel Dec 20, 2021
610a539
Revert "DEBUG simplify test to pass easier locally"
akavel Dec 20, 2021
c7cf301
scala resources sharing attempt
akavel Dec 20, 2021
7926d1a
try loading Enso snippet from resource
akavel Dec 20, 2021
bb9677d
import scala.io.Source
akavel Dec 20, 2021
9a69beb
build.sbt: try another way
akavel Dec 20, 2021
aa513dd
file load in build.sbt seems to have worked!
akavel Dec 20, 2021
6fc33db
drop the Compile/ use, still works
akavel Dec 20, 2021
18346d0
simpler unmanagedClasspath setting
akavel Dec 20, 2021
86f2f5b
fix which code is loaded from file
akavel Dec 20, 2021
bc36898
increase receive timeout to try and get it pass locally and in CI
akavel Dec 20, 2021
b78b1d1
add comments about keeping in sync
akavel Dec 20, 2021
d67c84d
s/should/need to
akavel Dec 20, 2021
94c928c
(cargo fmt)
akavel Dec 20, 2021
496c3c1
(changelog)
akavel Dec 20, 2021
00cd0b1
review: change unmanagedClasspath to be relative to baseDirectory
akavel Dec 20, 2021
258fccf
review: delete unnecessary trailing dot from console message
akavel Dec 20, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/gui/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
- [Fixed developer console errors related to Language Server (mentioning code
3003 and "Invalid version"), occurring during project opening and after new
node cration.][3186]
- [Fixed developer console error about failing to decode a notification
"executionContext/visualisationEvaluationFailed"][3193]

[3153]: https://github.com/enso-org/enso/pull/3153
[3166]: https://github.com/enso-org/enso/pull/3166
[3181]: https://github.com/enso-org/enso/pull/3181
[3186]: https://github.com/enso-org/enso/pull/3186
[3193]: https://github.com/enso-org/enso/pull/3193

# Enso 2.0.0-alpha.18 (2021-10-12)

Expand Down
17 changes: 17 additions & 0 deletions app/gui/controller/engine-protocol/src/language_server/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ pub enum Notification {
#[allow(missing_docs)]
#[serde(rename = "file/rootRemoved")]
ContentRootRemoved { id: Uuid },

/// Sent from server to the client to inform about a failure during execution of a
/// visualisation.
#[serde(rename = "executionContext/visualisationEvaluationFailed")]
VisualisationEvaluationFailed(VisualisationEvaluationFailed),
}

/// Sent from the server to the client to inform about a failure during execution of an execution
Expand All @@ -162,6 +167,18 @@ pub struct ExecutionFailed {
pub message: String,
}

/// Sent from server to the client to inform about a failure during execution of a visualisation.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
#[allow(missing_docs)]
#[serde(rename_all = "camelCase")]
pub struct VisualisationEvaluationFailed {
pub context_id: ContextId,
pub visualisation_id: Uuid,
pub expression_id: ExpressionId,
pub message: String,
pub diagnostic: Option<Diagnostic>,
}



// =======================
Expand Down
8 changes: 8 additions & 0 deletions app/gui/src/model/project/synchronized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,14 @@ impl Project {
content_roots.remove(id);
}
}
Event::Notification(Notification::VisualisationEvaluationFailed(update)) => {
error!(
logger,
"Visualisation evaluation failed in context {update.context_id} \
for visualisation {update.visualisation_id} of expression \
{update.expression_id}. Error: {update.message}."
akavel marked this conversation as resolved.
Show resolved Hide resolved
);
}
Event::Closed => {
error!(logger, "Lost JSON-RPC connection with the Language Server!");
let which = model::project::BackendConnection::LanguageServerJson;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,13 @@ use serde::Serialize;
const PADDING_TEXT: f32 = 10.0;
/// The Error Visualization preprocessor. See also _Lazy Visualization_ section
/// [here](http://dev.enso.org/docs/ide/product/visualizations.html).
pub const PREPROCESSOR_CODE: &str = r#"
x ->
result = Builtins.Ref.new "{ message: \"\"}"
x.catch err->
message = err.to_display_text
Builtins.Ref.put result ("{ \"kind\": \"Dataflow\", \"message\": " + message.to_json.to_text + "}")
Builtins.Ref.get result
"#;
// NOTE: contents of this const need to be kept in sync with Scala test in
// RuntimeVisualisationsTest.scala, used to verify the snippet's correctness
pub const PREPROCESSOR_CODE: &str = include_str!("inc/error_preprocessor.enso");

/// The context module for the `PREPROCESSOR_CODE`. See there.
// NOTE: contents of this const need to be kept in sync with Scala test in
// RuntimeVisualisationsTest.scala, used to verify the snippet's correctness
pub const PREPROCESSOR_MODULE: &str = "Standard.Base.Main";

/// Get preprocessor configuration for error visualization.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
x ->
result = Builtins.Ref.new '{ message: ""}'
x.catch err->
message = err.to_display_text
Builtins.Ref.put result ('{ "kind": "Dataflow", "message": ' + message.to_json.to_text + '}')
Builtins.Ref.get result

1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,7 @@ lazy val runtime = (project in file("engine/runtime"))
// Note [Unmanaged Classpath]
Compile / unmanagedClasspath += (`core-definition` / Compile / packageBin).value,
Test / unmanagedClasspath += (`core-definition` / Compile / packageBin).value,
Test / unmanagedClasspath += (baseDirectory.value / ".." / ".." / "app" / "gui" / "view" / "graph-editor" / "src" / "builtin" / "visualization" / "native" / "inc"),
Compile / compile / compileInputs := (Compile / compile / compileInputs)
.dependsOn(CopyTruffleJAR.preCompileTask)
.value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import java.nio.file.{Files, Path, Paths}
import java.util.UUID
import java.util.concurrent.{LinkedBlockingQueue, TimeUnit}

import scala.io.Source

@scala.annotation.nowarn("msg=multiarg infix syntax")
class RuntimeVisualisationsTest
extends AnyFlatSpec
Expand Down Expand Up @@ -1853,4 +1855,103 @@ class RuntimeVisualisationsTest
context.executionComplete(contextId)
)
}

it should "run internal IDE visualisation preprocessor catching error" in {
val contextId = UUID.randomUUID()
val requestId = UUID.randomUUID()
val visualisationId = UUID.randomUUID()
val moduleName = "Enso_Test.Test.Main"
val metadata = new Metadata

val idMain = metadata.addItem(77, 28)

val code =
"""from Standard.Builtins import all
|import Standard.Base.Data.List
|
|main =
| Error.throw List.Empty_Error
|""".stripMargin.linesIterator.mkString("\n")
val contents = metadata.appendToCode(code)
val mainFile = context.writeMain(contents)

// NOTE: below values need to be kept in sync with what is used internally by Rust IDE code
val visualisationModule = "Standard.Base.Main"
val visualisationCode = Source.fromResource("error_preprocessor.enso").mkString

// 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
val item1 = Api.StackItem.ExplicitCall(
Api.MethodPointer(moduleName, "Enso_Test.Test.Main", "main"),
None,
Vector()
)
context.send(
Api.Request(requestId, Api.PushContextRequest(contextId, item1))
)
val pushContextResponses =
context.receive(n = 4, timeoutSeconds = 60)
pushContextResponses should contain allOf (
Api.Response(requestId, Api.PushContextResponse(contextId)),
TestMessages.error(
contextId,
idMain,
Api.ExpressionUpdate.Payload.DataflowError(Seq())
),
context.executionComplete(contextId)
)
val loadedLibraries = pushContextResponses.collect {
case Api.Response(None, Api.LibraryLoaded(namespace, name, _, _)) =>
(namespace, name)
}
loadedLibraries should contain(("Standard", "Base"))

// attach visualisation
context.send(
Api.Request(
requestId,
Api.AttachVisualisation(
visualisationId,
idMain,
Api.VisualisationConfiguration(
contextId,
visualisationModule,
visualisationCode
)
)
)
)
val attachVisualisationResponses = context.receive(3)
attachVisualisationResponses should contain allOf (
Api.Response(requestId, Api.VisualisationAttached()),
context.executionComplete(contextId)
)
val Some(data) = attachVisualisationResponses.collectFirst {
case Api.Response(
None,
Api.VisualisationUpdate(
Api.VisualisationContext(
`visualisationId`,
`contextId`,
`idMain`
),
data
)
) =>
data
}
val stringified = new String(data)
stringified shouldEqual """{ "kind": "Dataflow", "message": "The List is empty."}"""
}
}