fix(codecs): #999 K-9 malformed wire values fail as each codec's documented exception (ArgumentException / ScriptWorkerProtocolException)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user