fix(codecs): #999 K-9 malformed wire values fail as each codec's documented exception (ArgumentException / ScriptWorkerProtocolException)

This commit is contained in:
Joseph Doherty
2026-12-03 10:49:44 -05:00
parent 22610df296
commit c42eeb3c69
4 changed files with 92 additions and 4 deletions
@@ -61,6 +61,21 @@ public static class VariantCodec
/// <returns>The boxed value.</returns>
/// <exception cref="ScriptWorkerProtocolException">An unknown tag, or a payload that does not match the tag.</exception>
public static object? Decode(Variant? variant)
{
try
{
return DecodeCore(variant);
}
catch (Exception ex) when (ex is OverflowException or ArgumentOutOfRangeException)
{
// #999 / review K-9: an out-of-range payload (a Byte carrying 300, DatetimeUtc ticks past DateTime.MaxValue)
// is a protocol fault like any other contradictory payload. OutOfProcessScriptRunner.Complete catches only
// ScriptWorkerProtocolException, so these used to fault the run task of a runner documented "never faults".
throw new ScriptWorkerProtocolException($"variant tagged {variant!.Type} is out of range: {ex.Message}", ex);
}
}
private static object? DecodeCore(Variant? variant)
{
if (variant is null) return null;
return variant.Type switch
@@ -112,7 +127,7 @@ public static class VariantCodec
var item = array.Items[i];
if (item.Type != array.ElementType && item.Type != Variant.Types.TypeTag.Null)
throw new ScriptWorkerProtocolException($"array of {array.ElementType} holds a {item.Type} element");
result.SetValue(Decode(item), i);
result.SetValue(DecodeCore(item), i);
}
return result;
}