fix(focas): #1036 a short macro/parameter payload publishes BadTypeMismatch, not BadCommunicationError

This commit is contained in:
Joseph Doherty
2026-12-03 14:56:25 -05:00
parent da467c9675
commit 52d2acad25
5 changed files with 56 additions and 5 deletions
@@ -1362,7 +1362,7 @@ public sealed class FocasWireClient : IAsyncDisposable, IDisposable
private static void RequireLength(byte[] payload, int length, string call)
{
if (payload.Length < length)
throw new FocasWireException($"{call} returned {payload.Length} bytes; expected at least {length}.", rc: null);
throw new FocasWirePayloadException($"{call} returned {payload.Length} bytes; expected at least {length}.");
}
private static bool IsTransientException(Exception exception)
@@ -62,3 +62,19 @@ public class FocasWireException : Exception
IsTransient = isTransient;
}
}
/// <summary>
/// A well-formed reply whose payload is too short to decode (#1036). The CNC answered and the session is
/// intact, so this is a decode refusal for the one tag - not a comms fault - and maps to
/// <c>BadTypeMismatch</c> rather than <c>BadCommunicationError</c> (which would degrade driver health and feed
/// the #527 watchdog over a shape problem that no reconnect can fix).
/// </summary>
public sealed class FocasWirePayloadException : FocasWireException
{
/// <summary>Initializes a new short/malformed-payload exception.</summary>
/// <param name="message">The exception message.</param>
public FocasWirePayloadException(string message)
: base(message, rc: null)
{
}
}
@@ -403,7 +403,7 @@ public sealed class WireFocasClient : IFocasClient
}
catch (FocasWireException ex)
{
return (null, ex.Rc is short rc ? FocasStatusMapper.MapFocasReturn(rc) : FocasStatusMapper.BadCommunicationError);
return (null, MapWireFailure(ex));
}
}
@@ -419,7 +419,7 @@ public sealed class WireFocasClient : IFocasClient
}
catch (FocasWireException ex)
{
return (null, ex.Rc is short rc ? FocasStatusMapper.MapFocasReturn(rc) : FocasStatusMapper.BadCommunicationError);
return (null, MapWireFailure(ex));
}
}
@@ -460,6 +460,20 @@ public sealed class WireFocasClient : IFocasClient
};
}
/// <summary>
/// The status a wire failure publishes: the CNC's own rc when it sent one; <c>BadTypeMismatch</c> for a reply
/// whose payload is too short to decode (#1036 - the session is intact and the CNC answered, so a shape problem
/// is a per-tag refusal, never a comms fault); otherwise <c>BadCommunicationError</c>.
/// </summary>
/// <param name="ex">The wire failure.</param>
/// <returns>The OPC UA status to publish for the tag.</returns>
internal static uint MapWireFailure(FocasWireException ex)
=> ex.Rc is short rc
? FocasStatusMapper.MapFocasReturn(rc)
: ex is FocasWirePayloadException
? FocasStatusMapper.BadTypeMismatch
: FocasStatusMapper.BadCommunicationError;
private async Task<(object? value, uint status)> ReadMacroAsync(
FocasAddress address, FocasDataType type, CancellationToken cancellationToken)
{
@@ -472,7 +486,7 @@ public sealed class WireFocasClient : IFocasClient
}
catch (FocasWireException ex)
{
return (null, ex.Rc is short rc ? FocasStatusMapper.MapFocasReturn(rc) : FocasStatusMapper.BadCommunicationError);
return (null, MapWireFailure(ex));
}
}