fix(scripting): #1109 byte[][] stays refused with a ByteString-specific reason

A script result has no ByteString-array form (its only byte shape is one flat
Byte array) and the worker wire has no ByteString or nested-array tag, so
byte[][] is left refused with every other jagged array (no new wire tag). Its
reason now says it is not an array of ByteStrings and offers both forms that
publish: a flat byte[] (SelectMany) or a string[] of Base64 blobs. Pinned by
ScriptResultMaterializerTests.
This commit is contained in:
Joseph Doherty
2026-12-04 22:09:47 -05:00
parent fce51769a4
commit ec17a83aea
3 changed files with 39 additions and 1 deletions
+1 -1
View File
@@ -140,7 +140,7 @@ processes:
previous value and status with only a server-log warning). A jagged array
(`int[][]`, `byte[][]`) is refused the same way since lmxopcua#1104 (`… cannot carry: an array of arrays …`, with a
flatten hint): it used to be the one result divergence — in process it was published as an array of Variants on a node
whose DataType is a scalar type, while the wire has no nested-array tag and the worker answered `unsupported type`. A returned collection (`List<double>`) is copied
whose DataType is a scalar type, while the wire has no nested-array tag and the worker answered `unsupported type`. `byte[][]` is not read as an array of ByteStrings (a script result has no ByteString-array form); its reason says so and also offers a `string[]` of Base64 blobs (lmxopcua#1109). A returned collection (`List<double>`) is copied
into a typed array by both runners first (lmxopcua#1092).
- **Attribution happens before release.** The worker's exit path runs attribution (strike, quarantine, suspect
marks) synchronously **before** it completes any evaluation the worker held, so a script killed for its deadline is
@@ -128,6 +128,18 @@ public static class ScriptResultMaterializer
private static void EnsurePublishable(Type type)
{
if (IsPublishable(type)) return;
// lmxopcua#1109: byte[][] reads like "an array of ByteStrings", which OPC UA does have (the OpcUaClient driver even
// surfaces a ByteString[] as byte[][]). But a script result has no ByteString-array form: the result rule's only
// byte shape is a one-dimensional Byte array, and the out-of-process wire (VariantCodec) has no ByteString or
// nested-array tag — adding one is deliberately out of scope. So byte[][] stays refused with every other jagged
// array; the reason just says so explicitly and offers the string[] form, which does publish.
if (type == typeof(byte[][]))
throw new ScriptResultException(
"The script returned a value of type 'Byte[][]', which an OPC UA node cannot carry: an array of arrays has " +
"no representation on a node whose DataType is a scalar type, and a script result cannot be an array of " +
"ByteStrings either (its only byte shape is one flat Byte array); return one flat byte[] " +
"(e.g. a.SelectMany(x => x).ToArray()) or a string[] of encoded blobs " +
"(e.g. a.Select(Convert.ToBase64String).ToArray()).");
if (type.IsArray && type.GetElementType()!.IsArray)
throw new ScriptResultException(
$"The script returned a value of type '{Describe(type)}', which an OPC UA node cannot carry: an array of " +
@@ -120,6 +120,32 @@ public sealed class ScriptResultMaterializerTests
.Message.ShouldStartWith("The script returned a value of type 'Int32[][]'");
}
/// <summary>
/// lmxopcua#1109: <c>byte[][]</c> stays refused (a script result has no ByteString-array form and the worker wire has
/// no tag for one — none was added), but its reason says so and offers the two forms that do publish. A lazy /
/// collection sequence of byte[] is refused earlier (its element type is itself a sequence), before it runs.
/// </summary>
[Fact]
public void A_byte_array_of_arrays_is_refused_with_a_ByteString_specific_reason()
{
ScriptResultMaterializer.IsPublishable(typeof(byte[][])).ShouldBeFalse();
var message = Should.Throw<ScriptResultException>(
() => ScriptResultMaterializer.Materialize(new[] { new byte[] { 1, 2 }, new byte[] { 3 } }, 100)).Message;
message.ShouldStartWith("The script returned a value of type 'Byte[][]', which an OPC UA node cannot carry: an array of arrays");
message.ShouldContain("cannot be an array of ByteStrings");
message.ShouldContain("SelectMany");
message.ShouldContain("Convert.ToBase64String");
var ran = 0;
Should.Throw<ScriptResultException>(() => ScriptResultMaterializer.Materialize(new List<byte[]> { new byte[] { 1 } }, 100));
Should.Throw<ScriptResultException>(() => ScriptResultMaterializer.Materialize(
Enumerable.Range(0, 2).Select(i => { ran++; return new[] { (byte)i }; }), 100));
ran.ShouldBe(0);
// The flat forms the reason offers do publish.
ScriptResultMaterializer.Materialize(new byte[] { 1, 2, 3 }, 100).ShouldBeOfType<byte[]>();
ScriptResultMaterializer.Materialize(new[] { "AQI=" }, 100).ShouldBeOfType<string[]>();
}
[Fact]
public void An_unpublishable_lazy_sequence_is_refused_before_it_runs()
{