mirror of
https://github.com/apple/pkl.git
synced 2026-04-23 16:58:37 +02:00
Handle null pathElements gracefully in message passing API (#480)
In messages "List Resources Response" and "List Modules Response", if `pathElements` and `error` are both null, default to an empty list.
This commit is contained in:
@@ -451,6 +451,8 @@ The response to <<list-resources-request>>.
|
|||||||
If successful, `pathElements` is set.
|
If successful, `pathElements` is set.
|
||||||
Otherwise, `error` is set.
|
Otherwise, `error` is set.
|
||||||
|
|
||||||
|
If neither are set, `pathElements` default to an empty list.
|
||||||
|
|
||||||
[source,pkl]
|
[source,pkl]
|
||||||
----
|
----
|
||||||
/// A number identifying this request.
|
/// A number identifying this request.
|
||||||
@@ -507,6 +509,8 @@ The response to <<list-modules-request>>.
|
|||||||
If successful, `pathElements` is set.
|
If successful, `pathElements` is set.
|
||||||
Otherwise, `error` is set.
|
Otherwise, `error` is set.
|
||||||
|
|
||||||
|
If neither are set, `pathElements` default to an empty list.
|
||||||
|
|
||||||
[source,pkl]
|
[source,pkl]
|
||||||
----
|
----
|
||||||
/// A number identifying this request.
|
/// A number identifying this request.
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ internal class ClientModuleKeyFactory(
|
|||||||
if (response.error != null) {
|
if (response.error != null) {
|
||||||
completeExceptionally(IOException(response.error))
|
completeExceptionally(IOException(response.error))
|
||||||
} else {
|
} else {
|
||||||
complete(response.pathElements!!)
|
complete(response.pathElements ?: emptyList())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else -> completeExceptionally(ProtocolException("unexpected response"))
|
else -> completeExceptionally(ProtocolException("unexpected response"))
|
||||||
|
|||||||
@@ -68,10 +68,10 @@ internal class ClientResourceReader(
|
|||||||
transport.send(request) { response ->
|
transport.send(request) { response ->
|
||||||
when (response) {
|
when (response) {
|
||||||
is ListResourcesResponse ->
|
is ListResourcesResponse ->
|
||||||
if (response.pathElements != null) {
|
if (response.error != null) {
|
||||||
complete(response.pathElements)
|
|
||||||
} else {
|
|
||||||
completeExceptionally(IOException(response.error))
|
completeExceptionally(IOException(response.error))
|
||||||
|
} else {
|
||||||
|
complete(response.pathElements ?: emptyList())
|
||||||
}
|
}
|
||||||
else -> completeExceptionally(ProtocolException("Unexpected response"))
|
else -> completeExceptionally(ProtocolException("Unexpected response"))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -294,6 +294,43 @@ class ServerTest {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `glob resources -- null pathElements and null error`() {
|
||||||
|
val reader = ResourceReaderSpec(scheme = "bird", hasHierarchicalUris = true, isGlobbable = true)
|
||||||
|
val evaluatorId = client.sendCreateEvaluatorRequest(resourceReaders = listOf(reader))
|
||||||
|
client.send(
|
||||||
|
EvaluateRequest(
|
||||||
|
requestId = 1,
|
||||||
|
evaluatorId = evaluatorId,
|
||||||
|
moduleUri = URI("repl:text"),
|
||||||
|
moduleText =
|
||||||
|
"""
|
||||||
|
res = read*("bird:/**.txt").keys
|
||||||
|
"""
|
||||||
|
.trimIndent(),
|
||||||
|
expr = "res"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
val listResourcesRequest = client.receive<ListResourcesRequest>()
|
||||||
|
client.send(
|
||||||
|
ListResourcesResponse(
|
||||||
|
requestId = listResourcesRequest.requestId,
|
||||||
|
evaluatorId = listResourcesRequest.evaluatorId,
|
||||||
|
pathElements = null,
|
||||||
|
error = null
|
||||||
|
)
|
||||||
|
)
|
||||||
|
val evaluateResponse = client.receive<EvaluateResponse>()
|
||||||
|
assertThat(evaluateResponse.result!!.debugYaml)
|
||||||
|
.isEqualTo(
|
||||||
|
"""
|
||||||
|
- 6
|
||||||
|
- []
|
||||||
|
"""
|
||||||
|
.trimIndent()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `glob resource error`() {
|
fun `glob resource error`() {
|
||||||
val reader = ResourceReaderSpec(scheme = "bird", hasHierarchicalUris = true, isGlobbable = true)
|
val reader = ResourceReaderSpec(scheme = "bird", hasHierarchicalUris = true, isGlobbable = true)
|
||||||
@@ -505,6 +542,47 @@ class ServerTest {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `glob module -- null pathElements and null error`() {
|
||||||
|
val reader =
|
||||||
|
ModuleReaderSpec(
|
||||||
|
scheme = "bird",
|
||||||
|
hasHierarchicalUris = true,
|
||||||
|
isLocal = true,
|
||||||
|
isGlobbable = true
|
||||||
|
)
|
||||||
|
val evaluatorId = client.sendCreateEvaluatorRequest(moduleReaders = listOf(reader))
|
||||||
|
|
||||||
|
client.send(
|
||||||
|
EvaluateRequest(
|
||||||
|
requestId = 1,
|
||||||
|
evaluatorId = evaluatorId,
|
||||||
|
moduleUri = URI("repl:text"),
|
||||||
|
moduleText = """res = import*("bird:/**.pkl").keys""",
|
||||||
|
expr = "res"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
val listModulesMsg = client.receive<ListModulesRequest>()
|
||||||
|
client.send(
|
||||||
|
ListModulesResponse(
|
||||||
|
requestId = listModulesMsg.requestId,
|
||||||
|
evaluatorId = evaluatorId,
|
||||||
|
pathElements = null,
|
||||||
|
error = null
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
val evaluateResponse = client.receive<EvaluateResponse>()
|
||||||
|
assertThat(evaluateResponse.result!!.debugRendering)
|
||||||
|
.isEqualTo(
|
||||||
|
"""
|
||||||
|
- 6
|
||||||
|
- []
|
||||||
|
"""
|
||||||
|
.trimIndent()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `glob module error`() {
|
fun `glob module error`() {
|
||||||
val reader =
|
val reader =
|
||||||
|
|||||||
Reference in New Issue
Block a user